Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Aug 19, 2013 Aug 19, 2013

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!

TOPICS
ActionScript
527
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 19, 2013 Aug 19, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 19, 2013 Aug 19, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2013 Aug 20, 2013
LATEST

daytxt does not exist when your code executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines