我正在嘗試偵聽在spark popup tileWindow中創建的事件。目標是在彈出窗口中發送和更新數組,以便在彈出窗口關閉時由調用應用程序接收數組。Flex:從parentApplication監聽customEvent
正如下面的內聯評論,我測試了它到達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);
}
}
}
在彈出,內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();
}
我modify.systemManager.addEventListener試過(MyCustomEvent.ON_SUBMIT ,rebuildCircuit);我得到一個類型錯誤:錯誤#1009「無法訪問空對象引用的屬性或方法。不確定 - 修改已實例化;是否有一些單獨的systemManager – RG1967 2011-05-22 14:56:08
如果上述不建議,你會建議我訂閱通過PopUp方法實現的事件? – RG1967 2011-05-22 14:57:06
什麼是「修改」?它是否是可視化組件?爲什麼不直接訂閱你的'Modify'事件?如果你想與你當前的代碼兼容,只需使用'systemManager.addEventListener (MyCustomEvent.ON_SUBMIT,rebuild);''而不是'addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);' – Constantiner 2011-05-22 15:01:49