Posted By

pfeisinger on 04/21/09


Tagged

timer counter backward


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Pingpongbal
swfgeek


Backwards Counting Timer


 / Published in: ActionScript 3
 

Code generates a Textfield and counts down from 20 to 0. Just paste code into an empty FLA-File on the first frame.

  1. var i:Number = 20;
  2. var myTimer:Timer = new Timer(1000);
  3. myTimer.addEventListener(TimerEvent.TIMER, countDown);
  4.  
  5. var myTextField:TextField = new TextField();
  6. myTextField.autoSize = TextFieldAutoSize.LEFT;
  7. addChild(myTextField);
  8.  
  9. var format:TextFormat = new TextFormat();
  10. format.font = "Verdana";
  11. format.color = "0xFF0000";
  12. format.size = 10;
  13. myTextField.defaultTextFormat = format;
  14.  
  15. function countDown(evt:TimerEvent)
  16. {
  17. trace("new Time: "+i);
  18. --i == -1 ? myTimer.reset() : myTextField.text = new String(i);
  19. }
  20.  
  21. myTimer.start();

Report this snippet  

You need to login to post a comment.