您需要监听键盘事件而不是鼠标事件。您在那里所做的是侦听图像上的 MouseEvent.CLICK 事件,这不是它应该如何工作的。
我的建议是你应该在舞台上监听键盘事件,然后检查是否按下了删除键。
还要检查这个
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/KeyboardEvent.html#includeExamplesSummary上的 adobe 文档
http://livedocs.adobe.com/flex/3/html/help.html?content=events_11.html
请参阅此示例
package {
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.*;
public class KeyboardEventExample extends Sprite {
private var child:Sprite = new Sprite();
private var bgColor:uint = 0x00CCFF;
private var size:uint = 80;
public function KeyboardEventExample() {
child.graphics.beginFill(bgColor);
child.graphics.drawRect(0, 0, size, size);
child.graphics.endFill();
addChild(child);
child.addEventListener(MouseEvent.CLICK, clickHandler);
child.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
child.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
}
private function clickHandler(event:MouseEvent):void {
stage.focus = child;
}
private function keyDownHandler(event:KeyboardEvent):void {
trace("keyDownHandler: " + event.keyCode);
trace("ctrlKey: " + event.ctrlKey);
trace("keyLocation: " + event.keyLocation);
trace("shiftKey: " + event.shiftKey);
trace("altKey: " + event.altKey);
}
private function keyUpHandler(event:KeyboardEvent):void {
trace("keyUpHandler: " + event.keyCode);
}
}
}