spring
spring

Reputation: 18487

Forcing update rendering of MX ProgressBar?

Would anyone know a method (or trick) to force a rendering update to an MX ProgressBar in manual mode when using setProgress?

I have a situation with a block of code containing a couple of for loops which take a bit of time to complete. It would be tedious to unwrap this code to generate events, etc.

Update

Let me expand on this with a bit of pseudo code. I want to update the progress bar during operations on the contents of an array. THe for loops blocks so the screen isn't updating. I've tried validateNow() but that had no effect.

Is there some non-convoluted way I can either unwrap the for loop or use AS3's event model to update a progress bar? (I'm more accustomed to multi-threaded environments where this sort of task is trivial).

   private function doSomeWork():void {
       progressBar.visible = true;

       for(var n = 0; n < myArray.length; n++){

            progressBar.setProgress(n, myArray.length);
            progressBar.label = "Hello World " + n;
            progressBar.validateNow(); // this has no apparent effect

            var ba:ByteArray = someDummyFunction(myArray[i]);
            someOtherFunction(ba);
        }

         progressBar.visible = false;
      }

Upvotes: 0

Views: 164

Answers (2)

akhil_mittal
akhil_mittal

Reputation: 24157

I am not sure what exactly is the problem. I tried the following code and it works without any need to validateNow.

  protected function button2_clickHandler(event:MouseEvent):void
  {
        for(var n:int = 0; n < 100; n = n+20){
        progressBar.setProgress(n, 100);
        progressBar.label = "Hello World " + n;
        // progressBar.validateNow(); 
        }
  }
  <mx:VBox width="100%" height="100%">
        <mx:ProgressBar id="progressBar"/>
        <mx:Button label="Update Progress" click="button2_clickHandler(event)"/>                
    </mx:VBox>

Upvotes: 0

Dave 114
Dave 114

Reputation: 193

In Flex, the screen is never updating while Actionscript code is running. It basically works like this:

  1. Execute all runnable Actionscript code.
  2. Update the screen.
  3. Repeat continuously.

To learn more details, google for [flex elastic racetrack]. But the above is the nut of what you need to understand.

If you don't want a long-running piece of code to freeze the screen, you'll have to break it up into chunks and execute them across multiple frames, perhaps within a FRAME_ENTER event handler.

Upvotes: 1

Related Questions