package {
import flash.display.*;
import flash.utils.*;
import flash.events.*;
public class Main extends Sprite {
private var timer:Timer;
private var rect:Sprite;
public function Main() {
rect = new Sprite( );
rect.x = 200;
rect.y = 200;
rect.graphics.lineStyle(1);
rect.graphics.beginFill(0x0000FF);
rect.graphics.drawRect(0, 0, 150, 75);
addChild(rect);
addEventListener(Event.ACTIVATE, activateListener);
addEventListener(Event.DEACTIVATE, deactivateListener);
timer = new Timer(50, 0);
timer.addEventListener(TimerEvent.TIMER, timerListener);
}
private function timerListener (e:TimerEvent):void {
rect.rotation += 10;
}
private function activateListener (e:Event):void {
timer.start( );
}
private function deactivateListener (e:Event):void {
timer.stop( );
}
}
}
|