6 Replies Latest reply on Jul 1, 2008 12:08 PM by coxmail2002

    Refresh TitleWindow during loop

      I have a titlewindow that contains a progressbar. I am using PopUpManager to open this titlewindow just before I go into a loop that does some calculations. I want to show this titlewindow which contains a progressbar during this loop, and update the progressbar accordingly.

      However the problem is that the titlewindow does not open or get refreshed until after the loop has completed. I cannot get it to show before this loop or during.

      Please help???

        • 1. Re: Refresh TitleWindow during loop
          atta707 Level 2
          you have a reference to title window once its shown using PopupManager class. Add a public property, let's just call it progress, and in your loop use the reference of the popup window to set the progress property.
          • 2. Re: Refresh TitleWindow during loop
            coxmail2002 Level 1
            Actually that is exactly what I am doing currently. I am calling a public method on the titlewindow class that updates the progressbar. That works fine, no problem. But the problem is that I cannot actually see this update happening until the loop has completely finished. Basically I think the screen is not refreshing and the titlewindow is not added to the displaylist until the loop has completed.

            Here's an example of my code:
            • 3. Re: Refresh TitleWindow during loop
              ntsiii Level 3
              Yes, any loop will complete in the current frame, and before the screen is allowed to update.

              Overcome this by breaking the loop up into discreet calls, and delaying the start of each iteration by using callLater().

              Keep an iteator value in an instance variable. Call the iterator function, and have it loop from the iterator value for some number of iterations, like 10, or 100. At the end of that, set the iterator var to the new index, and use callLater to call a function which sets the progress bar value, then call the iterator function again. You will need some way to stop the loop, either a hard-coded value of another instance var.

              • 4. Re: Refresh TitleWindow during loop
                coxmail2002 Level 1
                Thanks Tracy... that method sounds really promising. I will experiment.

                Would you be able to post an example code (even if very high-level) to illustrate your point?

                I appreciate your help!
                • 5. Re: Refresh TitleWindow during loop
                  ntsiii Level 3
                  Hmm, untested, almost psuedo code:
                  private var _iCurrentIteration:int = 0;
                  private var _iIterCount:int = 10;
                  private var _iMaxIndex:int = 1000;

                  private function pbIterator():void {
                  var iCount:int = _iCurrentIteration + _iIterCount;
                  for (var i:int = _iCurrentIteration; i<=iCount; i++){
                  //Do some work
                  _iCurrentIteration = i;

                  private function updatePB():void{
                  if (_iCurrentIteration <= _iMaxIndex) {

                  • 6. Re: Refresh TitleWindow during loop
                    coxmail2002 Level 1
                    Thanks so much Tracy. Works like a champ!!!