题
在空中的应用程序,我有下列代码:
theDialog=PopUpManager.createPopUp(此,TheDialogClass,true)作为TheDialogClass;theDialog.addEventListener(FlexEvent.CREATION_COMPLETE,cpuIntensiveCalc);
在结束cpuIntensiveCalc的对话被删除。对话通知用户"的东西是怎么回事,请站过。"
问题是,cpuIntensiveCalc开始之前对话。因此用户的经验是,应用程序冻结用于10秒没有指示,那么快速闪烁模式对话(不少于一个二)在屏幕上。
Adobe docs说这个约creation_complete
派当成分已经完成了它的建设, 财产处理、测量和绘图。
因此,这感觉就像正确的事件。
在名称的完整性,我也试过
theDialog=PopUpManager.createPopUp(此,TheDialogClass,true)作为TheDialogClass;cpuIntensiveCalc();
但是,有相同的结果。
TIA
没有正确的解决方案
其他提示
为此原因是,闪光的播放器就是个螺纹,你是阻止UI从反应到对话弹直到的数学块完成。
哈克修理时间...
你有两个选择。
(这一应工作,但是未经测试)包cpuIntensiveCalc()呼吁在callLater,使UI可以完成呈现在你面前阻止渲染。
或
使用"绿线",打破了你的处理,以便你不会完全阻UI处理。 看看.
(我只是有同样的问题=>即使这线是旧的,我只是想有助于我的解决方案)
(免责声明:这是一个有点丑,但他们说这是确定在UI层...;-))
Flex是个螺纹(至少从我们的开发的角度来看,我认为背后现场线被用于通过VM)
=>通常可执行代码在UI线,之后用户做了一些行动上的一个小部件。任何电话来更新用户界面组件(如setProgress或setLabel)将只能在屏幕上显示结束时呈现的周期(见再次UiComponent生命周期)。
=>在therory叫"cpuIntensiveCalc"在callLater会让框架显示您的弹出窗口之前执行的方法。
在实践中,我注意到你通常必须有一对夫妇的UI cylces之前弹出显示,像这样:
new MuchLaterRunner(popup, 7, cpuIntensiveCalc).runLater();
MuchLaterRunner被定义是这样的:
public class MuchLaterRunner
{
var uiComp:UIComponent;
var currentCounter = 0;
var cyclesToWaitBeforeExecution=0;
var command:Function;
public function MuchLaterRunner(uiComp:UIComponent, cyclesToWaitBeforeExecution:uint, command:Function)
{
this.uiComp = uiComp;
this.command = command;
this.cyclesToWaitBeforeExecution =cyclesToWaitBeforeExecution;
}
public function runLater() {
currentCounter ++;
if (currentCounter >= cyclesToWaitBeforeExecution) {
uiComp.callLater(command);
} else {
// wait one more cycle...
uiComp.callLater(runLater);
}
}
}
问题是同时呼吁setProgress之后:我们必须分cpuIntensiveCalc成小可调用的方法,可以跑在每个UI循环,否则的进度不会犯错,取得进展。
使用enterFrame事件上弹出式窗口。别忘了除去听者在enterFrame事件处理,否则cpu密集的方法将被称为在每一个框架,崩溃的程序。如果这不起作用在第一次,使用一个私人号码作为一个计数器并保留增加它在该框架处理程序-呼叫cpu重的方法,只有当该计数达到适当的价值。找到'适当的'值的线索和错误。
theDialog = PopUpManager.createPopUp(this, TheDialogClass, true) as TheDialogClass;
theDialog.addEventListener(Event.ENTER_FRAME, onEnterFrame);
private function onEnterFrame(e:Event):void
{
//can use theDialog instead of e.currentTarget here.
(e.currentTarget).removeEventListener(Event.ENTER_FRAME, onEnterFrame);
cpuIntensiveCalc();
}
//in case the above method doesn't work, do it the following way:
theDialog.addEventListener(Event.ENTER_FRAME, onEnterFrame);
private var _frameCounter:Number = 0;
private function onEnterFrame(e:Event):void
{
_frameCounter++;
var desiredCount:Number = 1;//start with one - increment until it works.
if(_frameCounter < desiredCount)
return;
//can use theDialog instead of e.currentTarget here.
(e.currentTarget).removeEventListener(Event.ENTER_FRAME, onEnterFrame);
cpuIntensiveCalc();
}