Backwards Counting Timer


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

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


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.