Flex:监听来自parentApplication的customEvent
我正在尝试监听在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 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 butSystemManager
. So if you want to use event bubbling from your pop-up window you should listen to events ofSystemManager
instance which is available through component'ssystemManager
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.试试这个:
您可以在这里找到解决问题的更详细的示例:http://xposuredesign.net/ ?p=53
干杯
Try this:
You can find a more elaborate example for the solution of your problem here: http://xposuredesign.net/?p=53
Cheers