Flex Flex 中的按键

发布于 2024-07-22 07:17:20 字数 434 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃酥萝莉 2024-07-29 07:17:20

这是针对 Flex 4 的。

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
            name="MyApp"
            width="480" height="480"
            creationComplete="init();">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        public function init():void
        {
            trace("init");
            this.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); 
        }

        private function keyDown(event:KeyboardEvent):void
        {
            trace(event.charCode);
        }       
</fx:Script></s:Application>

This is for flex 4.

<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
            name="MyApp"
            width="480" height="480"
            creationComplete="init();">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        public function init():void
        {
            trace("init");
            this.addEventListener(KeyboardEvent.KEY_DOWN, keyDown); 
        }

        private function keyDown(event:KeyboardEvent):void
        {
            trace(event.charCode);
        }       
</fx:Script></s:Application>
浅听莫相离 2024-07-29 07:17:20

您描述的第一个问题(在分派任何 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文