Flex Flex 中的按键
我有一个 Flex 中的小应用程序,其中定义了 2 个画布。 在其中一个上,我添加了控件,另一个用于绘制某些内容,并且未添加任何控件:
<mx:Canvas x="0" y="80" width="100%" height="520%" id="Canvas1"/>
<mx:Canvas x="0" y="0" width="100%" height="80" id="Canvas2"/>
我添加了一个处理到应用程序的 keydown 事件,但只有在我用鼠标单击第一个画布(其中的画布)后才会触发该事件已添加控件)。 否则,按下按键时不会触发该事件。
我尝试了几件事:将焦点设置在第二个画布上,将 keydown 处理程序添加到应用程序(此),舞台,画布...不幸的是,我没有找到触发 keydown 的解决方案,无论焦点在哪里。
I have an small application in flex in which I have defined 2 canvases. On one of them I added controls and the other one is used to draw something and no controls are added:
<mx:Canvas x="0" y="80" width="100%" height="520%" id="Canvas1"/>
<mx:Canvas x="0" y="0" width="100%" height="80" id="Canvas2"/>
I add an keydown event handled to the application but it is triggered only after I click with the mouse on the first Canvas(the one where controls have been added). Otherwise the event is not triggered when keys are presses.
I've tried several things: to set focus on the second canvas, to add the keydown handler to the application(this),stage, canvas... Unfortunately I didn't find a solution to trigger keydown no matter where the focus is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是针对 Flex 4 的。
This is for flex 4.
您描述的第一个问题(在分派任何 KeyboardEvents 之前必须单击鼠标)可能是由于浏览器没有将焦点集中到 Flex 应用程序本身。 您可以在 HTML 包装器中使用 Javascript 以编程方式将焦点集中到“body”元素的“onLoad”事件上的 Flex 应用程序。 我确信这在 Firefox 中有效,并且我相信它在 IE 中也能正常工作。 我会尝试挖掘相关的 Javascript 代码。
至于第二个问题,是否尝试向 Application.application 添加事件侦听器以捕获所有 KeyboardEvents?
The first problem you describe (having to click the mouse before any KeyboardEvents are dispatched) is likely due to the browser not giving focus to the Flex application itself. You can use Javascript in the HTML wrapper to programmatically give focus to the Flex app on the "body" element's "onLoad" event. I know for certain this works in Firefox and I believe it works okay in IE as well. I'll try to dig up the relevant Javascript code.
As far as the second problem, have tried adding an event listener to Application.application for catching all KeyboardEvents?