Posted By

heathbo on 10/05/10


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

davidino1978
donaldleegraham
tombarc
scottwatkins
fifkie


How to set, start, and use a Timer


 / Published in: ActionScript 3
 

delay is in milliseconds. repeat must be set to at least 1.

  1. import flash.utils.Timer;
  2. import flash.events.TimerEvent;
  3. import flash.events.Event;
  4.  
  5. private var myTimer:Timer = new Timer(delay, repeat);
  6.  
  7. myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  8. myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);
  9.  
  10. myTimer.start();
  11.  
  12. private function timerHandler(e:TimerEvent):void
  13. {
  14. repeat--;
  15. statusTextField.text = ((delay * repeat) / 1000) + " seconds left.";
  16. };
  17.  
  18. private function completeHandler(e:TimerEvent):void
  19. {
  20. statusTextField.text = "Times Up.";
  21. inputTextField.type = TextFieldType.DYNAMIC;
  22. };

Report this snippet  

You need to login to post a comment.