0 Replies Latest reply on Sep 17, 2009 12:20 PM by KontaCat

    ProgressBar in Event Mode Shows Progress ONLY at the End of the Operation - Why is that ?

    KontaCat

      //I have a class that does intensive work that I need to show its progress using
      //a progress bar. The progress is getting updated but it does not get updated
      //as the loop executes. I mean you do not see the actuall progress you just see
      //the progress bar in the final state. I had hard time looking in action script
      //forums. I believe the the trick is simple but I can not figure it out myself
      /as I am a beginner. thanks for any help/hints.

       

      mywork = new WorkClass();
      mywork.addEventListener(ProgressEvent.PROGRESS, UpdateProgress);
      myprogressbar.source = mywork;
      mywork.doWork();

      private function UpdateProgress(event:ProgressEvent):void
      {
         myprogressbar.setProgress(event.bytesLoaded, event.bytesTotal);
      }

      public class WorkClass extends EventDispatcher
      {
          public function doWork():void
          {
              for(var w:int = 0; w < 100000; w++)
              {

                  if (w%100 == 0)
                  {
                     this.dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS, false, false, w, 100000));
                  }
              }
          }
      }