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

Countdown timer not working

New Here ,
Aug 19, 2008 Aug 19, 2008
Hi,

I finished my countdown timer inside a page called pageHome. The problem
is that there´s something wrong with the code I put in the actions layer. I put the numbers of the timer inside a dynamic text field called "time_txt".

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at pageHome/updateTime()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()


Here´s the code on the timer

//var endDateate = new Date("Sun Aug 24 15:00:00 GMT+0200 2008");
var endDateate = new Date("Sun Aug 24 15:00:00 GMT+0200 2008");

var countdownTimer:Timer = new Timer(1000);
countdownTimer.addEventListener(TimerEvent.TIMER, updateTime);
countdownTimer.start();

function updateTime(e:TimerEvent):void
{
var nowate = new Date();
var timeLeft:Number = endDate.getTime() - now.getTime();
var seconds:Number = Math.floor(timeLeft / 1000);
var minutes:Number = Math.floor(seconds / 60);
var hours:Number = Math.floor(minutes / 60);
var days:Number = Math.floor(hours / 24);

seconds %= 60;
minutes %= 60;
hours %= 24;

var sec:String = seconds.toString();
var min:String = minutes.toString();
var hrs:String = hours.toString();
var d:String = days.toString();

if (sec.length < 2) {
sec = "0" + sec;
}

if (min.length < 2) {
min = "0" + min;
}

if (hrs.length < 2) {
hrs = "0" + hrs;
}

var time:String = d + ":" + hrs + ":" + min + ":" + sec;

time_txt.text = time;
}
TOPICS
ActionScript
349
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
Guest
Aug 19, 2008 Aug 19, 2008
LATEST
That error is thrown when you have undefined variables.

endDate.getTime() - now.getTime() should be endDateate.getTime() - nowate.getTime();

Cheers,
FlashTastic
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