Change text value in a TextField in a timer : Timer « Animation « Flash / Flex / ActionScript






Change text value in a TextField in a timer

 

package {

    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.events.TimerEvent;

    
    public class Main extends Sprite {
        var timer:Timer = new Timer(1000);
        
        private var _text:TextField;
        private var _start:uint;
        
        public function Main(  ) {
            _start = 0;
            _text = new TextField(  );
            addChild(_text);
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            timer.start(  );
        }
        
        private function onTimer(event:TimerEvent):void {
            _text.text = (timer.currentCount - _start) + " milliseconds";
        }
        
    }
}

        








Related examples in the same category

1.Creating a Timer
2.Repeating a Task over Time
3.Two timers are set, one for a square sprite and one for a circle sprite
4.Post-Event Updates for Timer Events
5.draws a single line with a random stroke style every 250 milliseconds. It uses clear( ) to erase the previously drawn line.
6.Creating Symbols Within Flash CS3
7.Defers the call to the deferredMethod( ) method for five seconds: