比方說,你有運行一些代碼,當您的遊戲結束:
myQuitBtn.addEventListener(MouseEvent.CLICK, quit, false, 0, true);
function quit(e:MouseEvent):void {
//do something, we quit the game
}
你可以很容易地將其更改爲偵聽的關鍵事件以下內容:
myQuitBtn.addEventListener(MouseEvent.CLICK, quit, false, 0, true);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
function keyUpHandler(e:KeyboardEvent):void {
//Check if the key pressed was the enter key
if(e.keyCode === 13){ //could also do `e.keyCode === Keyboard.ENTER`
quit();
}
}
//make the event argument optional so you can call this method directly and with a mouse listener
function quit(e:Event = null):void {
//remove the key listener
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false);
//do something, we quit the game
}
嘿BadFeelingAboutThis, –
你只是說喜,還是你有問題,只是提前輸入? – BadFeelingAboutThis
對不起,我失敗了。按下輸入,而我想獲得另一個空間。但非常感謝!你幫我了!不知道這很簡單。謝謝你的時間! –