2011-05-22 57 views
1

我正在嘗試偵聽在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(); 
     } 

回答

3

問題是Flex中彈出窗口的父容器不是Application或可視組件NT創建彈出,但SystemManager。因此,如果您想使用彈出式窗口中的事件冒泡,則應該聽取組件systemManager屬性中可用的SystemManager實例的事件。

至於我自己,我不喜歡在這種情況下使用冒泡,但訂閱彈出式窗口事件直接獲得鏈接到窗口的方法addPopUp

+0

我modify.systemManager.addEventListener試過(MyCustomEvent.ON_SUBMIT ,rebuildCircuit);我得到一個類型錯誤:錯誤#1009「無法訪問空對象引用的屬性或方法。不確定 - 修改已實例化;是否有一些單獨的systemManager – RG1967 2011-05-22 14:56:08

+0

如果上述不建議,你會建議我訂閱通過PopUp方法實現的事件? – RG1967 2011-05-22 14:57:06

+0

什麼是「修改」?它是否是可視化組件?爲什麼不直接訂閱你的'Modify'事件?如果你想與你當前的代碼兼容,只需使用'systemManager.addEventListener (MyCustomEvent.ON_SUBMIT,rebuild);''而不是'addEventListener(MyCustomEvent.ON_SUBMIT,rebuild);' – Constantiner 2011-05-22 15:01:49

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

乾杯

+0

嘗試過這種方法 - 根本沒有任何幫助 - 可能與上面說的Constantiner有關。 .. – RG1967 2011-05-22 14:53:59

+0

感謝有用的鏈接... – RG1967 2011-05-22 16:56:56