在设置数据之前,Flex弹出窗口会打开

时间:2012-06-19 16:30:23

标签: flex adobe popupwindow

我有一个从按钮打开的弹出窗口(selectReasonCode)。该按钮具有以下代码

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 

在选择原因代码屏幕上我有一个数据网格,其中填充了updateReasons方法中设置的值(由上述方法调用。

问题是我的弹出屏幕打开了空白。但是如果我在调试模式下在代码中添加一个断点并传递它,屏幕就会打开数据。我相信在数据实际设置之前屏幕会打开。这可能是真的吗?如果是这样,我如何确保在屏幕打开之前首先执行更新Reasons方法?

要排除调试模式...我在updateReasons代码之后添加了一行以导致错误。因此,首先显示错误,用户单击确定然后打开弹出窗口。然后在弹出窗口中显示数据。

1 个答案:

答案 0 :(得分:2)

  

我相信在数据实际设置之前屏幕会打开。   这可能是真的吗?

是!

  

如果是这样,我怎样才能确保更新Reasons方法得到   在屏幕打开之前先执行?

执行该方法,直到获得数据后才显示弹出窗口。在调试模式下执行可以在等待数据从远程服务器返回时为您提供所需的暂停;取决于调试点的位置。

但是,您可以像这样移动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);             
}