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

Animate CC2017 AS3 counddown timer

New Here ,
Aug 17, 2017 Aug 17, 2017

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

TOPICS
ActionScript
1.6K
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 17, 2017 Aug 17, 2017
LATEST

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:

Screenshot - 8_17_2017 , 3_04_45 PM.png

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