5 Replies Latest reply on Aug 4, 2010 8:11 AM by Ned Murphy

    timer counting up in hours:minutes:seconds:milliseconds format

    xxxheeroxxx Level 1

      Good day,

       

      Had a problem dealing with this kind of format.

      And I want the milliseconds in 2 digits only.

       

      Any help are greatly appreciated.

       

      Here's my code:

       

       

      intervalID = setInterval(this,"timerFunction",1);

       

      function timerFunction(){

      var msec:Number = getTimer();

       

      if (msec <= 0){

      play();

      return;

      }

       

      var sec:Number = Math.floor(msec / 1000);

      var min:Number = Math.floor(sec / 60);

      var hour:Number = Math.floor(min / 60);

       

      if(sec<10){

      secStr="0"+String(sec);

      }else{

      secStr=sec;

      }

       

      if(min<10){

      minStr="0"+String(min);

      }else{

      minStr=min;

      }

       

      if(hour<10){

      hourStr="0"+String(hour);

      }else{

      hourStr=hour;

      }

      //trace("min: "+min);

      //trace("sec: "+sec);

      //trace("msec: "+msec);

      _root.timerText = hourStr + ":" + minStr + ":" + secStr + ":" + msec;

      }

       

       

      Display result:

       

      00:00:01:1012

      00:00:02:2048