2015-07-19 45 views
0

幫助,我是新的AS2(閃光一般),我試圖做一個基本的菜單誰是由鍵盤控制。這裏是我的代碼Flash AS2 if(Key.getCode()== Key.ENTER)不起作用?

onClipEvent(enterFrame){ 
if(Key.isDown(Key.DOWN)) 
{ 
if(_root.menu1._currentframe==1) 
{ 
    _root.menu1.gotoAndStop(2); 
} 
} 

if(Key.isDown(Key.UP)) 
{ 
if(_root.menu1._currentframe==2) 
{ 
    _root.menu1.gotoAndStop(1); 
} 
} 

if (Key.getCode() == Key.ENTER) 
{ 
if(_root.menu1._currentframe==1) 
{ 
gotoAndStop("stage1"); 
} 
    else{ gotoAndStop("stage2"); } 
} 
} 

上下按鈕工作正常,但輸入不。有什麼建議麼?

+0

你在哪裏測試你的swf(獨立Flash播放器,瀏覽器,你的IDE)? – akmozo

回答

0

您的代碼可能正在工作,有時候在Flash環境或IDE中測試時,Key.ENTER事件並不總是顯示出來。

嘗試發佈您的代碼並在瀏覽器中運行它,可能會添加動態文本字段或使用控制檯進行調試。

您也可以使用keyListener對象而不是enterFrame事件。如果你想嘗試,嘗試將此代碼添加到時間軸上的一幀中

//import the external interface code 
import flash.external.ExternalInterface; 

// Create a key listener object; 
var keyListener:Object = new Object(); 

// Add the onKeyDown functionality 
keyListener.onKeyDown = function() { 

    // Convert incoming key presses to Ascii 
    var keyLetter = String.fromCharCode(Key.getAscii()); 
    // get the Key code 
    var keyCode = Key.getCode(); 
    // output the keyCode and keyLetter to the browser console/developer tools/firebug 
    // When testing in a browser press F12 on the keyboard to show them 
    // make sure you click on the SWF movie to get the focus then press keys 
    ExternalInterface.call("console.log", "["+keyCode+"] "+keyLetter) 
    // trace this so we can compare in Flash 
    trace("["+keyCode+"] "+keyLetter); 

    if (Key.isDown(Key.ENTER)) { 
     ExternalInterface.call("console.log", "ENTER key pressed!") 
    } 

}; 

// Add the listener 
Key.addListener(keyListener);