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 = 10;
for (var i:int = 0; i total; i++)
Just simulate a for loop with an ENTER_FRAME listener.
var total:int = 1;
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++;
}
Yikes! I don't think he actually wants the loop to take any longer than
necessary. I'm assuming he's got some sort of computationally expensive
operation (huge parse or something) that he wants to show the progress. How
about subdividing your loop into more manageable chunks that get called once
a
Hi,
the onenterframe will work, but you can approach it a little
differently, in pseudo:
onEnterFrame {
if (no items to process left) { clear onEnterFrame, signal done; }
set loop start time
while (currenttime - loop start time 100 ms) {
process loop item
}
update progressbar
}
greetz
4 matches
Mail list logo