我相信屏幕会在数据实际设置之前打开。这是真的吗?
是的!
如果是这样,我如何确保在屏幕打开之前先执行 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);
}