2012-06-19 66 views
0

我有一個從按鈕打開的彈出窗口(selectReasonCode)。所述按鈕具有選擇原因代碼屏幕我有填充了在updateReasons方法(這是通過上述方法稱爲設定值的數據格上下面的代碼在設置數據之前彈出彈出窗口

var selectReasonCode:SelectReasonCode = new SelectReasonCode();   
selectReasonCode.title = "Reason Codes"; 
selectReasonCode.showCloseButton = true; 
PopUpManager.addPopUp(selectReasonCode, this, true); 
PopUpManager.centerPopUp(selectReasonCode);    
selectReasonCode.updateReasons(reasonTypeId, rasonCds); //This sets the dataprovider 

問題是我的彈出屏幕打開了空白,但是如果我在調試模式下在代碼中添加一個斷點並通過它,屏幕將打開數據,我相信在數據真正設置之前屏幕會打開。是真的嗎?如果是這樣,我怎麼能保證在屏幕打開之前先更新Reasons方法?

To e xclude調試模式...我在updateReasons代碼之後添加了一行以導致錯誤。因此,首先顯示錯誤,用戶單擊確定,然後打開彈出窗口。數據顯示在彈出窗口中。

回答

2

我相信屏幕在數據實際設置之前打開。 這是真的嗎?

是的!

如果是這樣,我如何確保在屏幕打開之前先執行更新原因方法 ?

執行該方法,直到獲取數據後才顯示彈出窗口。在調試模式下執行可能會讓您在等待數據從遠程服務器返回時需要暫停;取決於調試點的位置。

但是,你可以移動updateReasons方法調用是這樣的:

var selectReasonCode:SelectReasonCode = new SelectReasonCode();   
selectReasonCode.title = "Reason Codes"; 
selectReasonCode.showCloseButton = true; 
selectReasonCode.updateReasons(reasonTypeId, rasonCds); //This sets the dataprovider 
PopUpManager.addPopUp(selectReasonCode, this, true); 
PopUpManager.centerPopUp(selectReasonCode);    

然而,在假設updateReasons打完一個異步服務調用,你將不得不等待,直到數據之前返回顯示彈出。概念上是這樣的:

// first make your pop up component an instance variable instead of a local variable to the method 
protected var selectReasonCode:SelectReasonCode;   


// in your method; create the instance like nromal 
selectReasonCode:SelectReasonCode = new SelectReasonCode(); 
selectReasonCode.title = "Reason Codes"; 
selectReasonCode.showCloseButton = true; 
selectReasonCode.updateReasons(reasonTypeId, rasonCds); //This sets the dataprovider 
selectReasonCode.addEventListener('someEventThatTellsMeDataIsReturn',onPopUpDataReturn); 


// finally in your data is available method, display the pop up using the PopUpManager 
protected function onPopUpDataReturn(event:Event):void{ 
    PopUpManager.addPopUp(selectReasonCode, this, true); 
    PopUpManager.centerPopUp(selectReasonCode);    
}