2016-03-01 62 views
0

我正在使用actionscript 3.0在Adobe Flash中構建地形訓練器。 我現在快完成了。在遊戲結束時我做了這個「退出」按鈕。 現在你可以點擊它來退出遊戲,但我也希望Enter鍵對退出按鈕做出反應。我真的試過在互聯網和計算器上查找它,但是我的搜索技能不夠先進,或者還沒有出現過同樣問題的人。在Flash遊戲中將Enter鍵鏈接到按鈕

我希望有人知道如何將輸入按鈕耦合到Flash中的按鈕。沒有涉及EditText。

感謝您的幫助,

賈斯汀

回答

2

比方說,你有運行一些代碼,當您的遊戲結束:

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 
} 
+0

嘿BadFeelingAboutThis, –

+0

你只是說喜,還是你有問題,只是提前輸入? – BadFeelingAboutThis

+0

對不起,我失敗了。按下輸入,而我想獲得另一個空間。但非常感謝!你幫我了!不知道這很簡單。謝謝你的時間! –