Skip to main content
Participant
August 20, 2013
Question

I made a countdown, but how can I make the digits change color everytime the second changes?

  • August 20, 2013
  • 1 reply
  • 550 views

Hi there.  I have been tasked with creating a countdown for a splash page.  I am not too familiar with flash so I took a couple online lessons and found some great sources to help me come up with a countdown which you can see here. http://www.swfcabin.com/open/1376959235 

Now, my colleauge asked if it is possible to have the numbers turn red on each circle, which i was able to accomplish here: http://www.swfcabin.com/open/1376958743

If you notice, the countdown no longer works on on the second example and I keep getting an error message and I honestly have no idea what's going on.  I tried playing with the timeline with no success and my capacity with ActionScript 3 is beginner at best.  I was actually able to find an online tutorial that gave me some code to use and i just played around with it for my use.

Here is the error message i get:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at BirthdayCountdown_fla::MainTimeline/loop()

Here is the code I am using:

var targetDate:Date = new Date(2014, 7, 8, 15);

addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
var nowDate:Date = new Date();
var ms:Number = targetDate.getTime() - nowDate.getTime();
var sec:Number = Math.floor(ms/1000);
var min:Number = Math.floor(sec/60);
var hr:Number = Math.floor(min/60);
var day:Number = Math.floor(hr/24);

sec = sec % 60;
min = min % 60;
hr = hr % 24;

daytxt.text = day.toString();
hrtxt.text = (hr < 10) ? "0"+hr.toString() : hr.toString();
mintxt.text = (min < 10) ? "0"+min.toString() : min.toString();
sectxt.text = (sec < 10) ? "0"+sec.toString() : sec.toString();
}

and here is a screenshot of my timeline.

Thank you SOOOOO much in advance for your help!!  It is truly appreciated!

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 20, 2013

to find your error, click file>publish settings>swf and tick "permit debugging".  retest.

the problematic line number will be in the error message.  on that line you are trying to reference something that doesn't exist when your code executes.  most likely that's one of your textfields.

Participant
August 20, 2013

Thanks kglad.  This is what i got

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at BirthdayCountdown_fla::MainTimeline/loop()[BirthdayCountdown_fla.MainTimeline::frame1:18]

Here is another screenshot just incase

kglad
Community Expert
Community Expert
August 20, 2013

daytxt does not exist when your code executes.