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

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

问题描述

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

In an AIR application I have the following code:

theDialog = PopUpManager.createPopUp( this, TheDialogClass, true ) as 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.

Adobe 文档这样说到 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( this, TheDialogClass, true ) as 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 是单线程的(至少从我们开发者的角度来看,我认为幕后线程是由虚拟机使用的)

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

=> 在用户对小部件执行某些操作之后,您通常会在 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).

=> 理论上,在 callLater 中调用cpuIntensiveCalc"将使框架在执行该方法之前显示您的弹出窗口.

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

但在实践中,我注意到在显示弹出窗口之前您通常必须有几个 UI 循环,如下所示:

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周期运行,否则progressbar不会,err,progress.

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天全站免登陆