1 Reply Latest reply on Dec 11, 2007 9:18 AM by Tigomark

    Who's got the timer

    Tigomark
      Hello,

      I have a very functional timer here that I am using but I would like to get some advice on how to make it better.

      Code:

      private function getDaysUntil():void {
      // creates a new five-minute Timer
      var minuteTimer:Timer = new Timer(1000, 300);

      // designates listeners for the interval and completion events
      minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
      minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

      // starts the timer ticking

      minuteTimer.start();
      }

      public function onTick(evt:TimerEvent):void {
      var minuteTimer:Timer = evt.target as Timer;
      lblTimeUntil.text = minuteTimer.currentCount.toString();
      }

      public function onTimerComplete(evt:TimerEvent):void
      {
      var minuteTimer:Timer = evt.target as Timer;
      minuteTimer.reset();

      minuteTimer.start();
      }


      I would like to be able to split the time into minutes and seconds.

      Also I would like to get it to count down instead of up.
        • 1. Re: Who's got the timer
          Tigomark Level 1
          Found it

          public function onTick ( evt:TimerEvent ) :void { var minuteTimer:Timer = evt.target as Timer; var lvSecondsRemaining:int = minuteTimer.repeatCount - minuteTimer.currentCount; var lvMinutes:int = lvSecondsRemaining / 60; var lvSeconds:int = lvSecondsRemaining - ( lvMinutes * 60 ); var lvSecondsText:String = lvSeconds.toString(); if( lvSeconds < 10 ) lvSecondsText = "0" + lvSecondsText; lblTimeUntil.text = lvMinutes.toString() + ":" + lvSecondsText; } // onTick