Flex:监听来自parentApplication的customEvent

发布于 2024-11-08 15:22:30 字数 1618 浏览 0 评论 0原文

我正在尝试监听在 Spark 弹出窗口中创建的事件。目的是在弹出窗口中发送和更新数组,以便在弹出窗口关闭时由调用应用程序接收。

正如下面内联评论的那样,我已经测试过它达到了在 popUp 中调度事件的点,并且从未在主应用程序中被监听。我缺少什么?

我的自定义事件如下:

package folder1
{           
import flash.events.Event;
import mx.collections.ArrayCollection;

public class MyCustomEvent extends Event
{
    public var myDataToPass:ArrayCollection;
    public static const ON_SUBMIT:String = "submit";

    public function MyCustomEvent (type:String, bubbles:Boolean=true, cancelable:Boolean=false)
    {
        super(type, bubbles, cancelable);
    }
 }
}

在 PopUp 中,在tileWindow 中我有

public var newEvent:MyCustomEvent=new MyCustomEvent("submit");
        private function closePopUp():void{

            newEvent.myDataToPass=elementData;
            dispatchEvent(newEvent);
            trace(" came into close function"); //this is tested
            PopUpManager.removePopUp(this);

        }

最后在调用应用程序中我有这个结构

private function createModifyPopUp(evt:MouseEvent):void{
            var modify:Modify=new Modify();
            modify.elementData=elements;
            modify.eventTarget=evt.currentTarget;
            addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);

            trace("came  into modify"); //this is tested
            PopUpManager.addPopUp(modify,this,true);
            PopUpManager.centerPopUp(modify);
        }



        private function rebuild(evt:MyCustomEvent):void{
            trace("got listened");//NEVER REACHES HERE
            elements=evt.myDataToPass;
            buildfunction(); 
        }  

I am trying to listen to an event created in a spark popup tileWindow. The aim is to get an array sent and updated in the popUp, to be received by the calling application, when the popUp is closed.

As commented inline below, I have tested that it reaches the point of dispatching event in the popUp- and never gets listened in main application. What am i missing?

My customEvent is as follows:

package folder1
{           
import flash.events.Event;
import mx.collections.ArrayCollection;

public class MyCustomEvent extends Event
{
    public var myDataToPass:ArrayCollection;
    public static const ON_SUBMIT:String = "submit";

    public function MyCustomEvent (type:String, bubbles:Boolean=true, cancelable:Boolean=false)
    {
        super(type, bubbles, cancelable);
    }
 }
}

In the PopUp, within tileWindow I have

public var newEvent:MyCustomEvent=new MyCustomEvent("submit");
        private function closePopUp():void{

            newEvent.myDataToPass=elementData;
            dispatchEvent(newEvent);
            trace(" came into close function"); //this is tested
            PopUpManager.removePopUp(this);

        }

Finally in the calling application I have this structure

private function createModifyPopUp(evt:MouseEvent):void{
            var modify:Modify=new Modify();
            modify.elementData=elements;
            modify.eventTarget=evt.currentTarget;
            addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);

            trace("came  into modify"); //this is tested
            PopUpManager.addPopUp(modify,this,true);
            PopUpManager.centerPopUp(modify);
        }



        private function rebuild(evt:MyCustomEvent):void{
            trace("got listened");//NEVER REACHES HERE
            elements=evt.myDataToPass;
            buildfunction(); 
        }  

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

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

发布评论

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

评论(2

那些过往 2024-11-15 15:22:30

问题是 Flex 中弹出窗口的父容器不是创建弹出窗口的 Application 或可视组件,而是 SystemManager。因此,如果您想从弹出窗口使用事件冒泡,您应该监听 SystemManager 实例的事件,该实例可通过组件的 systemManager 属性获得。

就我自己而言,我不喜欢在这种情况下使用冒泡,而是订阅弹出窗口事件,直接在 addPopUp 方法中获取指向窗口的链接。

The problem is the parent container of pop ups in Flex is not an Application or visual component which creates pop up but SystemManager. So if you want to use event bubbling from your pop-up window you should listen to events of SystemManager instance which is available through component's systemManager property.

As for myself I prefer not to use bubbling in such cases but subscribe to pop-up window events directly getting link to the window in addPopUp method.

吾性傲以野 2024-11-15 15:22:30

试试这个:

private function createModifyPopUp(evt:MouseEvent):void{
            var modify:Modify=new Modify();
            modify.elementData=elements;
            modify.eventTarget=evt.currentTarget;
            modify.addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);

            trace("came  into modify"); //this is tested
            PopUpManager.addPopUp(modify,this,true);
            PopUpManager.centerPopUp(modify);
        }

您可以在这里找到解决问题的更详细的示例:http://xposuredesign.net/ ?p=53

干杯

Try this:

private function createModifyPopUp(evt:MouseEvent):void{
            var modify:Modify=new Modify();
            modify.elementData=elements;
            modify.eventTarget=evt.currentTarget;
            modify.addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);

            trace("came  into modify"); //this is tested
            PopUpManager.addPopUp(modify,this,true);
            PopUpManager.centerPopUp(modify);
        }

You can find a more elaborate example for the solution of your problem here: http://xposuredesign.net/?p=53

Cheers

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