callLater is a great suggestion, thank you. Unfortunately, was not
helpful in this case. Even delaying the adds by a callLater does not
allow the progressBar to update visually.

 

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Peeyush Tuli
Sent: Tuesday, March 02, 2010 10:18 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Trouble with ProgressBar and manual updates.

 

  

it might be that all the processing is too much to be displayed in the
same frame. So this might help you

http://jimmyflex.blogspot.com/2007/11/dont-forget-power-of-calllater.htm
l


~Peeyush
http://www.mds.asia

http://jimmyflex.blogspot.com/2007/11/dont-forget-power-of-calllater.htm
l



On Wed, Mar 3, 2010 at 6:53 AM, Christopher McArthur
<cmcart...@riotgames.com> wrote:

  

Using Flex3 in AIR standalone application.

 

I have a ton of children I need to add to a Canvas dynamically. When I
do this, it takes a long time. So I wanted to display a loading bar to
the user. 

 

I create a Timer, and every time the timer ticks, I update the
loadingBar and I add the child. I also update a textField with the
loading progress as a debug tool.

 

What I find is that the textField _always_ updates correctly in
realtime, but USUALLY the progress bar does NOT update at all until the
entire sequence is finished. If I make the tick time long enough, then
the progress bar works, but this time seems very dependent on
performance of the individual machine.

 

My question is, how do I know what the lowest possible tick time I can
use to make the progress bar update correctly is? Why does it work with
the Text field just fine? Or is there a better pattern I could be using
to do this correctly?

 

As you can see from the code, I tried some things like
"updateAfterEvent" and "invalidateDisplayList" to see if I could get it
to update faster, but those did not work (unless I set the tick time
high).

 

code here:

 

private var pendingElementsToAdd:Array;

private var totalElementstoAdd:int;

private static const TIME_BETWEEN_ADDS:Number = 20;

 

      

private function addElements(newElements:Array):void

{

      this.pendingElementsToAdd = newElements;

      this.totalElementstoAdd = this.pendingElementsToAdd.length;

      var newEventTimer:Timer = new Timer(TIME_BETWEEN_ADDS,
newElements.length);

      newEventTimer.addEventListener(TimerEvent.TIMER,
onTimerAddNewElement);

      newEventTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
finishAddingElements);

      newEventTimer.start();

}

 

private function onTimerAddNewElement(event:TimerEvent):void

{                 

                  this.loadingBar.setProgress(this.totalElementstoAdd -
this.pendingElementsToAdd.length, this.totalElementstoAdd);

                  this.loadingText.text = "Elements To Load: " +
this.pendingElementsToAdd.length;

                  

                  event.updateAfterEvent();

                  this.loadingBar.invalidateDisplayList();

                  

                  this.addChild(this.pendingElementsToAdd.pop());

}



Reply via email to