捕获事件
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
[SWF(width="400", height="300", backgroundColor="#ff0000", frameRate="31")]
public class activescript3 extends Sprite
{
private var _sprite:Sprite;
public function activescript3()
{
stage.focus = this;
_sprite = new Sprite();
addChild(_sprite);
_sprite.graphics.beginFill(0x00ff00);
_sprite.graphics.drawCircle(100,100,200);
_sprite.graphics.endFill();
_sprite.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
_sprite.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
_sprite.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardDown);
_sprite.addEventListener(KeyboardEvent.KEY_UP,onKeyboardUp);
}
private function onMouseDown(event:MouseEvent):void{
_sprite.graphics.lineStyle(1,0,1);
_sprite.graphics.moveTo(mouseX,mouseY);
_sprite.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
}
private function onMouseUp(event:MouseEvent):void{
_sprite.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMove);
}
private function onMouseMove(event:MouseEvent):void{
_sprite.graphics.lineTo(mouseX,mouseY);
}
private function onKeyboardDown(event:KeyboardEvent):void{
trace("key code is" + event.charCode);
}
private function onKeyboardUp(event:KeyboardEvent):void{
trace("key code is" + event.charCode);
}
}
}
阅读(909) | 评论(0) | 转发(0) |