全局事件监听器,当焦点位于 texiInput 内时
我正在尝试创建一个全局事件监听器。一切正常,KeyboardEvent.KEY_DOWN
一直触发..除了 textInput 具有焦点的情况。
这是我附加侦听器的方法:
FlexGlobals.topLevelApplication.systemManager.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, true);
我已经尝试了两种方法(使用捕获和不使用捕获)。我缺少什么?
感谢您的宝贵时间:)
I'm trying to make a global eventListener. Everything works fine, the KeyboardEvent.KEY_DOWN
fires all the time .. except the cases when the textInput has a focus.
Here's how I attach listener:
FlexGlobals.topLevelApplication.systemManager.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, true);
I've tried both (use capture and without it). What am I missing?
Thanks for your time :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我不知道为什么您使用
systemManager
作为侦听器对象,因为它不是显示列表的一部分,因此它无法获取冒泡事件。其次,使用 FlexGlobals 并不是最好的做事方式(就我个人而言,除了将它用于弹出窗口之外,我看不出有什么理由应该使用它)。如果您想收听全球活动,只需将其放在舞台上即可。每个视图组件都有一个“stage”属性,它指向 Flex 应用程序的主阶段。试试这个:
First, I don't know why you're using the
systemManager
as your listener object since it's not part of the display list, hence it can't get bubbling events. Second, using FlexGlobals isn't the best way of doing things (personally, other than using it for popups, I don't see many reasons why you should use it).If you want to listen for a global event, just put it on the stage. Every view component has a 'stage' property which points to the main stage of your flex app. Try this:
嗯...我不太明白问题出在哪里。
这是一个简单的应用程序:
这是一个输出:
Key Down Handler: key = 65
Top Level Application Key Down Handler: key = 65
System Manager Key Down Handler: key = 65
Key Down Handler: key = 83
Top Level Application Key Down Handler: key = 83
System Manager Key Down Handler: key = 83
Key Down Handler: key = 68
顶级应用程序 Key Down Handler: key = 68
System Manager Key Down Handler: key = 68
如您所见,我在应用程序中创建了三个不同的组件并使用三种不同的方法来捕获事件。在所有情况下(当其中一个组件具有焦点时)事件都会被触发并捕获。
也许你没有告诉我们一些重要的事情。
Hmm... I don't really understand what's the problem.
Here's a simple app:
Here's an output:
Key Down Handler: key = 65
Top Level Application Key Down Handler: key = 65
System Manager Key Down Handler: key = 65
Key Down Handler: key = 83
Top Level Application Key Down Handler: key = 83
System Manager Key Down Handler: key = 83
Key Down Handler: key = 68
Top Level Application Key Down Handler: key = 68
System Manager Key Down Handler: key = 68
As you can see, I created three different components in the application and used three different methods to catch the event. And in all cases(when one of the components have focus) event is fired and catched.
Probably you didn't tell us something important.