Skip to main content
Participant
August 17, 2017
Question

Animate CC2017 AS3 counddown timer

  • August 17, 2017
  • 1 reply
  • 1592 views

hi

I try to make a countdown timer in animate CC

in 1 layer I have a dynamic text in format 00:00:00:00 and another layer  the following AS3 code to Wight to that dynamic text but nothing happens

name of dynamic text is time_txt

AS3 code

stop();

var year:Number = 17;

var month:Number = 9;

var day : Number = 10;

var finalDate:Date = new Date(year,month-1,day);

var timer:Timer = new Timer(1000);

timer.addEventListener(TimerEvent.TIMER, updateTime);

timer.start();

function updateTime(event:TimerEvent):void{

   

   var now:Date = new Date();

   var remainTime:Number = finalDate.getTime() - now.getTime();

   

   if (remainTime >0) {

      

      var secs:Number = Math.floor(remainTime/1000);

      var mins:Number = Math.floor(secs/60);

      var hours:Number = Math.floor(mins/60);

      var days:Number = Math.floor(hours/24);

      

      var secsText:String = (secs%60).toString();

      var minsText:String = (mins%60).toString();

      var hoursText:String = (hours%24).toString();

      var daysText:String = days.toString();

      

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

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

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

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

         

     

      var time: String = daysText + ":" + hoursText + ":" + minutesText + ":" + secondsText;

    time_txt.text = time;

   }

}

is there a way to debug the AS3 code ?

or can I attach the complete fla code here ? so some can see what I do wrong

or do some one have a finished count down timer i can have a look on ?

best regards

Rene Pedersen

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
August 17, 2017

using the trace function is, by far, the most important debugging tool to use with actionscript.  doing that would reveal your finalDate has passed (9/10/1917). ie use

year=2017

also, enable 'permit debugging' in the publish settings (file>publish settings) to pinpoint the line of code triggering error messages: