How to set, start, and use a Timer


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.