Two timers are set, one for a square sprite and one for a circle sprite : Timer « Animation « Flash / Flex / ActionScript






Two timers are set, one for a square sprite and one for a circle sprite

 

package {
    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    
    public class Main extends Sprite {
        private var _square:Sprite;
        private var _circle:Sprite;
        
        
        public function Main(  ) {
            _square = new Sprite(  );
            _square.graphics.beginFill(0xff0000);
            _square.graphics.drawRect(0, 0, 100, 100);
            _square.graphics.endFill(  );
            addChild(_square);
            _square.x = 100;
            _square.y = 50;
            
            _circle = new Sprite(  );
            _circle.graphics.beginFill(0x0000ff);
            _circle.graphics.drawCircle(50, 50, 50);
            _circle.graphics.endFill(  );
            addChild(_circle);
            _circle.x = 100;
            _circle.y = 200;
            
            var squareTimer:Timer = new Timer(50, 0);
            squareTimer.addEventListener(TimerEvent.TIMER, onSquareTimer);
            squareTimer.start(  );
            
            var circleTimer:Timer = new Timer(100, 0);
            circleTimer.addEventListener(TimerEvent.TIMER, onCircleTimer);
            circleTimer.start(  );
        }
        
        private function onSquareTimer(event:TimerEvent):void {
            _square.x++;
        }
        
        private function onCircleTimer(event:TimerEvent):void {
            _circle.x++;
        }
    }
}

        








Related examples in the same category

1.Creating a Timer
2.Repeating a Task over Time
3.Change text value in a TextField in a timer
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: