我含viewstacks和他们的孩子的一个模块内这样做。 在模块的creationComplete调用的OnInit()。
当我在这里面,模块和preSS一个ViewStack的的孩子的一个输入,它不不是在所有调用的侦听器函数(BP这里面不被打到)。
私有函数的OnInit():无效{
this.addEventListener(KeyboardEvent.KEY_DOWN,关键pressed);
}
专用功能键pressed(EVT:KeyboardEvent的):无效
{//这个断点永远不会触及pressing屏幕的关键
如果(evt.key code == Keyboard.ENTER)
{
//做这个
}
}
解决方案
您应该增加关键听众上演对象:
私有函数的OnInit():无效{
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,关键pressed);
}
I am doing this inside a module containing viewstacks and their childs. Calling onInit() on creationComplete of module.
When I am inside one of the childs of a viewstack of this module and press Enter, it doesnt not invoke the listener function at all (bp inside this does not get hit).
private function onInit():void{
this.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}
private function keyPressed(evt:KeyboardEvent):void
{//this breakpoint never gets hit on pressing a key in screen
if (evt.keyCode == Keyboard.ENTER)
{
//do this
}
}
解决方案
You should add key listeners to stage objects:
private function onInit():void{
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
}