键盘事件的事件侦听器不在模块中侦听 [英] Event listener to keyboard event not listening in a module

查看:37
本文介绍了键盘事件的事件侦听器不在模块中侦听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个包含视图堆栈及其子项的模块中执行此操作.在模块的创建完成时调用 onInit().

I am doing this inside a module containing viewstacks and their childs. Calling onInit() on creationComplete of module.

当我在此模块的视图堆栈的其中一个子项中并按 Enter 键时,它根本不会调用侦听器函数(其中的 bp 不会被击中).

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);
}

这篇关于键盘事件的事件侦听器不在模块中侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆