Flex:从parentApplication中侦听customEvent

时间:2011-05-22 14:17:49

标签: flex event-handling popup

我正在尝试收听在spark popup tileWindow中创建的事件。目的是在popUp关闭时获取popUp中发送和更新的数组,以便由调用应用程序接收。

如下面的内联评论,我已经测试过它在popUp-中达到调度事件的点,并且永远不会在主应用程序中被监听。我错过了什么?

我的customEvent如下:

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(); 
        }  

2 个答案:

答案 0 :(得分:3)

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

至于我自己,我不想在这种情况下使用冒泡,而是订阅弹出窗口事件,直接在addPopUp方法中链接到窗口。

答案 1 :(得分:1)

试试这个:

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

干杯