Just simulate a for loop with an ENTER_FRAME listener.

var total:int = 10000;
var i:int = 0;
root.addEventListener(Event.ENTER_FRAME, simLoop);
private function simLoop(e:Event):void
{
  if(i >= total){ root.removeEventListener(Event.ENTER_FRAME, simLoop); };
  pbar.setProgress(i, total);
  i++;
}

On Fri, Nov 21, 2008 at 4:23 PM, Mac Angell <[EMAIL PROTECTED]> wrote:

> Is it possible to show the progress of a code loop on a progress bar?
> For example, if I have a progress bar named "pbar" already defined on
> the stage, and I execute the following function:
>
>
>
> private function init():void
>
> {
>
>      var total:int = 100000;
>
>      for (var i:int = 0; i < total; i++)
>
>      {
>
>            pbar.setProgress(i, total);
>
>            stage.invalidate();
>
>      }
>
> }
>
>
>
> The progress bar jumps from 0% to 100% after a long pause (the for loop
> executing). I am pretty sure this happens because the entire code loop
> executes before the next frame gets rendered. As you can see I even
> tried stage.invalidate(), but my guess is that it just tells the stage
> to update on the next frame, instead of forcing the stage to update at
> that exact time.
>
>
>
> Is there any way to get this to work in AS3? In other words, is there
> any way to force the screen to update in the middle of a code thread?
>
>
>
> Thanks!
>
>
>
> -Mac Angell
>
>
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
--Joel Stransky
stranskydesign.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to