我正在尝试收听在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();
}
答案 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
干杯