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


Flash / Flex / ActionScript examples » Animation » Timer »

 

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(00100100);
            _square.graphics.endFill(  );
            addChild(_square);
            _square.x = 100;
            _square.y = 50;
            
            _circle = new Sprite(  );
            _circle.graphics.beginFill(0x0000ff);
            _circle.graphics.drawCircle(505050);
            _circle.graphics.endFill(  );
            addChild(_circle);
            _circle.x = 100;
            _circle.y = 200;
            
            var squareTimer:Timer = new Timer(500);
            squareTimer.addEventListener(TimerEvent.TIMER, onSquareTimer);
            squareTimer.start(  );
            
            var circleTimer:Timer = new Timer(1000);
            circleTimer.addEventListener(TimerEvent.TIMER, onCircleTimer);
            circleTimer.start(  );
        }
        
        private function onSquareTimer(event:TimerEvent):void {
            _square.x++;
        }
        
        private function onCircleTimer(event:TimerEvent):void {
            _circle.x++;
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Animation
» Timer