有没有办法将键盘事件添加到 Flex 顶级应用程序中?
我正在将图像加载到我的 Flex 应用程序中,并尝试通过键盘移动图像。我向应用程序添加了一个事件侦听器,但图像不会移动。我怎样才能得到它,以便 Flex 4 顶级应用程序可以使用键盘侦听器。我弄清楚如何让键盘事件监听器工作的唯一可能的方法是添加到文本字段。
<?xml version="1.0" encoding="utf-8"?>
<fx:Declarations>
</fx:Declarations>
<s:creationComplete>
<![CDATA[
//this.addEventListener(MouseEvent.MOUSE_MOVE, movePlayer);
this.addEventListener(KeyboardEvent.KEY_DOWN, movePlayerKeys);
]]>
</s:creationComplete>
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
private function movePlayer(e:MouseEvent): void {
trace("Moving mouse",e.localX, e.localY);
}
private function movePlayerKeys(e:KeyboardEvent): void {
trace("key pressed:",e.charCode);
// add controls class here.
}
]]>
</fx:Script>
<player:Player id="player" x="10" y="10"/>
考虑到我什至没有得到键盘事件的跟踪。
I'm loading an image in to my flex application and I'm trying to move the image via keyboard. I added an event listener to the application but the image will not move. How can I get it so that the flex 4 top level application can use the keyboard listener. The only possible way I'm figuring out how to get the keyboard event listener to work is add to to a text field.
<?xml version="1.0" encoding="utf-8"?>
<fx:Declarations>
</fx:Declarations>
<s:creationComplete>
<![CDATA[
//this.addEventListener(MouseEvent.MOUSE_MOVE, movePlayer);
this.addEventListener(KeyboardEvent.KEY_DOWN, movePlayerKeys);
]]>
</s:creationComplete>
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
private function movePlayer(e:MouseEvent): void {
trace("Moving mouse",e.localX, e.localY);
}
private function movePlayerKeys(e:KeyboardEvent): void {
trace("key pressed:",e.charCode);
// add controls class here.
}
]]>
</fx:Script>
<player:Player id="player" x="10" y="10"/>
Take into consideration I'm not even getting the trace on the keyboard event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用舞台添加键盘侦听器,它可以工作(当然,如果应用程序具有焦点)。
Use stage to add keyboard listeners, it works (if application has focus, of course).