Flash AS2 if (Key.getCode() == Key.ENTER) 不起作用?

问题描述 投票:0回答:2

帮助,我是AS2(一般Flash)的新手,我正在尝试制作一个由键盘控制的基本菜单。这是我的代码

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"); }
}
}

向上和向下按钮可以正常工作,但 Enter 不行。有什么建议吗?

flash
2个回答
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);

0
投票

Stage.addEventListener(MouseEvent.RIGHT_CLICK,function():void{}); 你能把上面的代码转换成AS2.0吗? 上面的代码在AS3.0上运行良好。 禁用正确的 cli

© www.soinside.com 2019 - 2024. All rights reserved.