Mate 未捕获 EventMap 中的事件 [Flex]

发布于 2024-08-17 19:03:38 字数 1979 浏览 4 评论 0原文

在我的 AIR 应用程序中,我在捕获事件映射中调度的事件时遇到问题。 分派事件的类如下所示:

Shortcuts.as

[Event(name="centeredZoomOut", type="flash.events.Event")]

public class Shortcuts extends EventDispatcher
{
    // Event Names
    public static const CENTERED_ZOOM_OUT:String = "centeredZoomOut";

    public function Shortcuts(target:IEventDispatcher=null)
    {
        super(target);
        NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
    }

    private function onKeyUp(event:KeyboardEvent):void
    {
        this.dispatchEvent(new Event(CENTERED_ZOOM_OUT, true));
    }
}    

我知道该事件是通过调试来分派的,但它没有被以下事件映射捕获。

ShortcutMap.mxml

<?xml version="1.0" encoding="utf-8"?>
<EventMap 
xmlns="http://mate.asfusion.com/"
xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.FlexEvent;
        import models.Shortcuts;
    ]]>
</mx:Script>

<EventHandlers type="{ Shortcuts.CENTERED_ZOOM_OUT }">
    <MethodInvoker generator="{ShortCutExample}" method="showAlert" arguments="{['centeredZoom']}" />
</EventHandlers>

这是名为“ShortCutExample”的主应用程序文件

ShortCutExample.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication 
xmlns:mx="http://www.adobe.com/2006/mxml" 
xmlns:maps="maps.*"
layout="absolute"  
creationComplete="init()">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import models.Shortcuts;

        private var shortcuts:Shortcuts;

        private function init():void
        {
            this.shortcuts = new Shortcuts();
        }

        public function showAlert(value:String):void
        {
            Alert.show(value);
        }
    ]]>
</mx:Script>
<maps:ShortcutMap/>

</mx:WindowedApplication>

为什么我的事件映射未捕获事件?

In my AIR application I am having problems catching dispatched events in my eventmap.
The class that is dispatching the events looks like this:

Shortcuts.as

[Event(name="centeredZoomOut", type="flash.events.Event")]

public class Shortcuts extends EventDispatcher
{
    // Event Names
    public static const CENTERED_ZOOM_OUT:String = "centeredZoomOut";

    public function Shortcuts(target:IEventDispatcher=null)
    {
        super(target);
        NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
    }

    private function onKeyUp(event:KeyboardEvent):void
    {
        this.dispatchEvent(new Event(CENTERED_ZOOM_OUT, true));
    }
}    

I know that the event is getting dispatched from debugging it, but it is not getting caught by the following eventmap.

ShortcutMap.mxml

<?xml version="1.0" encoding="utf-8"?>
<EventMap 
xmlns="http://mate.asfusion.com/"
xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.FlexEvent;
        import models.Shortcuts;
    ]]>
</mx:Script>

<EventHandlers type="{ Shortcuts.CENTERED_ZOOM_OUT }">
    <MethodInvoker generator="{ShortCutExample}" method="showAlert" arguments="{['centeredZoom']}" />
</EventHandlers>

Here is the main application file called "ShortCutExample"

ShortCutExample.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication 
xmlns:mx="http://www.adobe.com/2006/mxml" 
xmlns:maps="maps.*"
layout="absolute"  
creationComplete="init()">

<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import models.Shortcuts;

        private var shortcuts:Shortcuts;

        private function init():void
        {
            this.shortcuts = new Shortcuts();
        }

        public function showAlert(value:String):void
        {
            Alert.show(value);
        }
    ]]>
</mx:Script>
<maps:ShortcutMap/>

</mx:WindowedApplication>

Why is my eventmap not catching the event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

挽清梦 2024-08-24 19:03:38

因为我没有将该对象添加到显示列表中,并且它没有扩展 DisplayObject,所以事件映射没有捕获所调度的事件。为了解决这个问题,创建一个 GlobalDispatcher 类型的私有变量并从该变量分派事件。

private var dispatcher:GlobalDispatcher = new GlobalDispatcher();
...
this.dispatcher.dispatchEvent(new ShortCutEvent(ShortCutEvent.CENTERED_ZOOM_OUT, true));

Because I was not adding the object to the display list and it did not extend DisplayObject the dispatched events were not being caught by the eventmap. To solve this problem create a private variable of type GlobalDispatcher and dispatch your events from that variable.

private var dispatcher:GlobalDispatcher = new GlobalDispatcher();
...
this.dispatcher.dispatchEvent(new ShortCutEvent(ShortCutEvent.CENTERED_ZOOM_OUT, true));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文