as 3.0使用键盘代码
as 3.0使用键盘代码
package cn.com.webstudio{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class KeyCodes extends Sprite {
private var box:Sprite;
public function KeyCodes() {
init();
}
private function init():void {
box=new Sprite();
addChild(box);
box.graphics.beginFill(0xff0000);
box.graphics.drawRect(0,0,40,40);
box.graphics.endFill();
box.x=stage.stageWidth / 2;
box.y=stage.stageHeight / 2;
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardEvent);
}
public function onKeyboardEvent(event:KeyboardEvent):void {
switch (event.keyCode) {
case Keyboard.DELETE:
removeChild (box)
}
}
}
}
补充:flash教程,As3.0