0

我有一个从按钮打开的弹出窗口(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 方法(由上述方法调用)中设置的值。

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

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

4

1 回答 1

2

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

是的!

如果是这样,我如何确保在屏幕打开之前先执行 update 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);             
}
于 2012-06-19T16:41:03.300 回答