(I had the same problem =>, even if this thread is old, I just wanted to make my decision)
(disclaimer: this is a little ugly, but they say what's normal in the user interface layer ... ;-))
Flex is single-threaded (at least from the point of view of our developer, I think that VMs are used behind scene streams)
=> you usually execute your code in the user interface thread after the user has taken some action on the widgets. Any UI component update invocation (for example, setProgress or setLabel) will only be displayed on the screen at the end of the rendering cycle (see Again the UiComponent Life Cycle).
=> In the expression calling "cpuIntensiveCalc" in callLater, let the environment show your popup before executing the method.
In practice, however, I noticed that you usually should have a couple of UI dials before the popup appears, for example:
new MuchLaterRunner(popup, 7, cpuIntensiveCalc).runLater();
MuchLaterRunner is defined as follows:
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 {
The problem arises when setProgress is called after this: we have to divide cpuIntensiveCalc into small invoked methods that can be run in each cycle of the user interface, otherwise the progress panel will not, error, progress.