gpt4 book ai didi

windows - Spark WindowedApplication,监听keyUp事件

转载 作者:可可西里 更新时间:2023-11-01 10:37:46 25 4
gpt4 key购买 nike

我有一个 WindowedApplication,我需要监视 keyUp 以便我可以在按下转义键时关闭应用程序。但是,我的代码不起作用:

<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"
keyUp="windowedapplication1_keyUpHandler(event)">

<fx:Script>
<![CDATA[

protected function windowedapplication1_keyUpHandler(event:KeyboardEvent):void
{
//Monitor key press {ESC}
if(event.keyCode == 27){
exit();
}
else{
trace("key = " + event.keyCode);
}
}

]]>
</fx:Script>

似乎这个事件根本没有触发,我什至试图覆盖 keyUpHandler 并追踪一些信息,但没有。

最佳答案

我找到了 this similar question在 Adob​​e 论坛上,它帮助解决了问题。

我通过监听 applicationComplete 然后在处理程序中将 keyUp 监听器附加到 stage 来解决。

<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"
applicationComplete="init()">

<fx:Script>
<![CDATA[

protected function init():void
{
stage.addEventListener(KeyboardEvent.KEY_UP, windowedapplication1_keyUpHandler);
}

protected function windowedapplication1_keyUpHandler(event:KeyboardEvent):void
{
//Monitor key press {ESC}
if(event.keyCode == 27){
exit();
}
else{
trace("key = " + event.keyCode);
}
}

]]>
</fx:Script>

关于windows - Spark WindowedApplication,监听keyUp事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15500021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com