有没有办法在Flex顶级应用程序中添加Keyboardevent?
问题描述:
我正在加载图像到我的flex应用程序中,并试图通过键盘移动图像。我向应用程序添加了事件侦听器,但图像不会移动。我如何得到它,以便flex 4顶级应用程序可以使用键盘监听器。我想知道如何让键盘事件监听器工作的唯一可能方式是添加到文本字段。有没有办法在Flex顶级应用程序中添加Keyboardevent?
<?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"/>
请考虑到我还没有得到关于键盘事件的跟踪。
你能发表你的代码样本吗? – 2011-03-07 15:42:17