我正在尝试收听在火花弹出窗口 tileWindow 中创建的事件。目的是在弹出窗口关闭时在弹出窗口中发送和更新一个数组,由调用应用程序接收。
正如下面内联评论的那样,我已经测试过它是否达到了弹出窗口中调度事件的点 - 并且从未在主应用程序中被监听。我错过了什么?
我的自定义事件如下:
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);
}
}
}
在弹出窗口中,在磁贴窗口中,我有
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();
}
问题是 Flex 中弹出窗口的父容器不是创建弹出窗口的Application
或视觉组件,而是SystemManager
。因此,如果您想从弹出窗口中使用事件冒泡,您应该侦听SystemManager
实例的事件,该事件可通过组件的 systemManager
属性获得。
至于我自己,我不喜欢在这种情况下使用冒泡,而是订阅弹出窗口事件,直接addPopUp
方法获取指向窗口的链接。
试试这个:
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
干杯