FLEX:对话框不会立即显示 [英] FLEX: dialog not display immediately

查看:185
本文介绍了FLEX:对话框不会立即显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AIR应用程序中,我有以下code:

In an AIR application I have the following code:

theDialog = PopUpManager.createPopUp(这一点,TheDialogClass,真)为TheDialogClass;   theDialog.addEventListener(FlexEvent.CREATION_COMPLETE,cpuIntensiveCalc);

theDialog = PopUpManager.createPopUp( this, TheDialogClass, true ) as TheDialogClass; theDialog.addEventListener(FlexEvent.CREATION_COMPLETE, cpuIntensiveCalc);

目前cpuIntensiveCalc的端部被除去的对话框。该对话框会告知用户说:事情是怎么回事,请袖手旁观。

At the end of cpuIntensiveCalc the dialog is removed. The dialog informs the user that "something is going on, please stand by."

的问题是,cpuIntensiveCalc启动对话平之前。因此,用户的体验是应用程序的10个无指示,则模态对话框快速闪烁(不到一秒钟)在屏幕上冻结。

The problem is that cpuIntensiveCalc starts before the dialog draws. So the user experience is that the application freezes for 10 seconds with no indicator, then the modal dialog flashes quickly (less than a second) on screen.

Adob​​e的文档说这一下CREATION_COMPLETE

The Adobe docs say this about creation_complete

当组件完成构建调度,   属性处理,测量,布置和绘制。

Dispatched when the component has finished its construction, property processing, measuring, layout, and drawing.

所以,这种感觉就像正确的事件。
在完整的名字,我也尝试过

So this feels like the correct event.
In the name of completeness, I also tried

theDialog = PopUpManager.createPopUp(这一点,TheDialogClass,真)为TheDialogClass;   cpuIntensiveCalc();

theDialog = PopUpManager.createPopUp( this, TheDialogClass, true ) as TheDialogClass; cpuIntensiveCalc();

但有同样的效果。

TIA

推荐答案

(我刚做了同样的问题=>即使这个线程是老了,我只是想贡献我的解决方案)

(I just had the same issue => even if this thread is old, I just wanted to contribute my solution)

(免责声明:这是一个有点难看,但他们说这是确定在UI层... ;-))

(disclaimer: this is a bit ugly, but they say that's ok in the UI layer... ;-) )

Flex是单线程的(至少从我们的开发者的角度来看,我觉得现场的线程背后所使用的VM)

Flex is single threaded (at least from our developer's perspective, I think behind the scene threads are used by the VM)

=>您通常执行的code在UI线程,在用户做了一个小部件的一些动作。任何呼叫到更新UI组件(像setProgress或setLabel)将只被呈现在屏幕上的呈现周期结束(再次参见UiComponent生命周期)。

=> you typically execute your code in the UI thread, after the user did some action on a widget. Any call to update a UI component (like setProgress or setLabel) will only be rendered on screen at the end of the render cycle (see again UiComponent life cycle).

=>在therory呼叫cpuIntensiveCalc在使用callLater将让执行该方法之前,该框架显示弹出式窗口。

=> In therory calling "cpuIntensiveCalc" in a callLater will let the framework display your popup before executing the method.

但在实践中,我注意到你通常必须有一对夫妇UI cylces的弹出显示之前,像这样的:

In practice though, I noticed you typically have to have for a couple of UI cylces before the popup be displayed, like this:

new MuchLaterRunner(popup, 7, cpuIntensiveCalc).runLater();

MuchLaterRunner被定义是这样的:

MuchLaterRunner being defined like this:

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周期跑出小的可调用的方法,否则进度不会,错了,进步。

The issue is the same when calling setProgress afterward: we must divide cpuIntensiveCalc into small callable methods that can be ran at each UI cycle, otherwise the progressbar won't, err, progress.

这篇关于FLEX:对话框不会立即显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆