Actionscript 3 项目中整个聚焦元素的Enter按钮事件的操作脚本
嗨,我正在开发一个AdobeAIR应用程序。我已经为我的项目中的所有按钮实现了点击事件。现在我想为重点按钮添加“回车”键盘事件。有没有简单的方法来实现它?请告诉我……你可以做这类事情:Actionscript 3 项目中整个聚焦元素的Enter按钮事件的操作脚本,actionscript-3,apache-flex,actionscript,air,Actionscript 3,Apache Flex,Actionscript,Air,嗨,我正在开发一个AdobeAIR应用程序。我已经为我的项目中的所有按钮实现了点击事件。现在我想为重点按钮添加“回车”键盘事件。有没有简单的方法来实现它?请告诉我……你可以做这类事情: <?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
addedToStage="addEnterFeature()">
<fx:Script>
<![CDATA[
private function addEnterFeature() : void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
}
private function onKeyDown(e : KeyboardEvent) : void
{
if(e.keyCode == Keyboard.ENTER && stage.focus is Button)
// Simulate a mouse click on current focused button
Button(stage.focus).dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
private function onButtonClick(e : Event) : void
{
trace("Button click handler");
}
]]>
</fx:Script>
<s:Button label="Test" id="myButton" />
</s:WindowedApplication>
如果您在应用程序(具有焦点)中的每个按钮上使用Enter键,它将模拟鼠标单击。谢谢您的回复,我将实施并通知您。我有超过50个mxml文件在我的项目中,我需要实现这对所有的mxml吗?你只需要在你的应用程序中运行此代码一次。因为它没有链接到UI,而是链接到舞台。