我需要一个事件监听器来按键盘上的删除按钮。
我尝试使用此代码:
stage.addEventListener(KeyboardEvent.KEY_UP, deleteItem);
function deleteItem(e:KeyboardEvent) {
if(e.charCode == 46){
trace('1');
}
}
但不起作用。请帮帮我!
答案 0 :(得分:0)
stage.addEventListener(KeyboardEvent.KEY_UP, keyboardEventUPHandler, false, 0, true);
function keyboardEventUPHandler(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.DELETE)
{
//Keyboard.DELETE = 46
//do something
}
}
答案 1 :(得分:-2)
stage.addEventListener(KeyboardEvent.KEY_UP, deleteItem);
应该是
stage.addEventListener(KeyboardEvent.KEY_DOWN, deleteItem);