12 Replies Latest reply on Feb 2, 2010 7:04 PM by miguel8312

    Progress bar does not update help

    miguel8312 Level 3
      public
      
      
      var record:Array = new Array();
      
      
      var Sub:String = new String();               Sub == 
      
      "Y";
      
      var obj:Object;
      
      var obj2:Object;
      
      var result:String = new String(fr.data);
                     record = result.split(
      
      "\r\n");// carriage return begin new line
      
      //trace(result);
      
      for ( var i:int = 0; i<record.length; i++)// ++ stands for increment
                     {
                     obj = 
      new Object();               fields = record[i].split(
      
      ",");// separate each field by comma.
                     count=count+1;
                     obj.col1 = fields[0];
                     obj.col2 = fields[1];
                     obj.col3 = fields[2];    
      /// fields is an array that grabs the information from the position given
                     obj.col4 = fields[3];    
      /// then we push the field into the objext and then the object into the record
                     obj.col5 = fields[4];    
      /// then bind to datagrid.
                     obj.col6 = fields[5];
                     obj.col7 = fields[6];
                     obj.col8 = fields[7];
                     obj.col9 = fields[8];
                     obj.col10 = fields[9];
                     obj.col11 = fields[10];
                     obj.col12 = fields[11];
                     obj.col13 = i+1;
                     pbProgress.setProgress( (count % 10), 100 );
      
      trace(pbProgress.setProgress( (count % 10), 100 ));
      
      
      
      
      
      
      
      
      
       function eventComplete(event:Event):void{
      

      here is my code  i have a progress bar that does not show the 100% until i completed loaded the array into the datagrid what i would like to do is show a percentage everytime the it loops through the array can anyone point me in the right direction.

      Thanks

      Miguel

        • 1. Re: Progress bar does not update help
          miguel8312 Level 3
          public
          
           function eventComplete(event:Event):void{
          
          
          var record:Array = new Array();
          
          var Sub:String = new String();
                         Sub == 
          
          "Y";
          
          
          var obj:Object;
          
          
          var obj2:Object;
          
          
          var result:String = new String(fr.data);               record = result.split(
          
          "\r\n");// carriage return begin new line
          
          //trace(result);
          
          for ( var i:int = 0; i<record.length; i++)// ++ stands for increment
                         {
                         obj = 
          new Object();
                         fields = record[i].split(
          
          ",");// separate each field by comma.
                         count=count+1;
                         obj.col1 = fields[0];
                         obj.col2 = fields[1];
                         obj.col3 = fields[2];    
          /// fields is an array that grabs the information from the position given
                         obj.col4 = fields[3];    
          /// then we push the field into the objext and then the object into the record
                         obj.col5 = fields[4];    
          /// then bind to datagrid.
                         obj.col6 = fields[5];
                         obj.col7 = fields[6];
                         obj.col8 = fields[7];
                         obj.col9 = fields[8];
                         obj.col10 = fields[9];
                         obj.col11 = fields[10];
                         obj.col12 = fields[11];
                         obj.col13 = i+1;
                         pbProgress.setProgress( (count % 10), 100 );
          
          trace(pbProgress.setProgress( (count % 10), 100 ));
          
          
          
          
          
          
          
          
          • 2. Re: Progress bar does not update help
            miguel8312 Level 3

            bump any ideas?

            • 3. Re: Progress bar does not update help
              Peter deHaan Level 4

              Did you set the ProgressBar control's mode to "manual"?

               

              Peter

              • 4. Re: Progress bar does not update help
                miguel8312 Level 3
                <mx:ProgressBar
                
                visible="{fr != null}"
                mode="manual" 
                label="" 
                id="pbProgress" 
                labelPlacement="center"
                 width="162"/>
                
                
                
                


                here is my progress bar it is set to manual i like for it to update everytime it loops but it does not. The only time it updates is when it finished loading the datagrid.

                 

                Is rather frustuating.

                • 5. Re: Progress bar does not update help
                  Peter deHaan Level 4

                  I tested with your ProgressBar code and a Timer and it seemed to work as expected in Flex 3.5:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();">
                      
                      <mx:Script>
                          <![CDATA[
                              import mx.controls.Alert;
                     
                              private const MAX:uint = 10;
                              private var count:uint = 0;
                              private var tmr:Timer = new Timer(1000, 11);
                              
                              private function init():void {
                                  tmr.addEventListener(TimerEvent.TIMER, tmr_timer);
                                  tmr.addEventListener(TimerEvent.TIMER_COMPLETE, tmr_complete);
                                  tmr.start();
                              }
                              
                              private function tmr_timer(evt:TimerEvent):void {
                                  pbProgress.setProgress(count, MAX);
                                  count++;
                              }
                              
                              private function tmr_complete(evt:TimerEvent):void {
                                  Alert.show(evt.type);
                              }
                          ]]>
                      </mx:Script>
                      
                      <mx:Label id="sdkVer" initialize="sdkVer.text = mx_internal::VERSION;" selectable="true" />
                      
                      <mx:ProgressBar id="pbProgress"
                                      mode="manual" 
                                      label="" 
                                      labelPlacement="center"
                                      width="162"/>
                      
                  </mx:Application>
                  
                  
                  
                  

                   

                  Peter

                  • 6. Re: Progress bar does not update help
                    miguel8312 Level 3

                    thank you Pete but how do i incorporate in a loop ? if i seen examples similar to this in the past but never with a loop?... Thanks for all your help thus far.

                    • 7. Re: Progress bar does not update help
                      Peter deHaan Level 4

                      Well, what are you trying to show the progress of? How far the user has scrolled down a DataGrid? The % loaded of an external file? I'm unclear on when your event handler gets called which is updating the ProgressBar.

                       

                      Peter

                      • 8. Re: Progress bar does not update help
                        miguel8312 Level 3
                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                        <mx:Script>
                             <![CDATA[
                                  private function init():void{
                                  var i:int; 
                                  for (i = 0; i < 50; i++) 
                                  { 
                                      trace(i); 
                                  pbProgress.setProgress(i, 50);
                                       var delayTimer:Timer;
                                       delayTimer = new Timer(10000, 100 );
                                       delayTimer.start();
                                  }
                        
                                  }     
                             ]]>
                             
                        </mx:Script>
                        <mx:ProgressBar 
                                  mode="manual" 
                                  label="" 
                                  id="pbProgress" 
                                  labelPlacement="center" 
                                  width="162"/>
                        <mx:Button click="init()" x="75" y="49"/>
                             
                                  
                             
                        </mx:Application>
                        


                        in my application the user clicks a browser button which i then call filereference to loop through a csv file that then gets parsed and inputted into a datagrid. what i would like to do is to put a progress bar to gauge how  far along is the loop, because the application goes blank for a few seconds or minutes depending on the loop. I have taken the example to a much simplistic level like the code above I guess im not allow to use the progressbar in this fashion?.... sorry if i sound like an idiot im just a flex noob .

                        thanks

                        Miguel

                        • 9. Re: Progress bar does not update help
                          Peter deHaan Level 4

                          The problem with your example above is that the for loop will execute very quickly so you probably will just see the ProgressBar jump straight to 100% complete. Also, the Timer wont really do, well, anything since you arent listening for a timer or timerComplete event.

                           

                          How about modifying your original example to use this code instead in the for loop:

                           

                          pbProgress.setProgress( i, record.length );

                           

                           

                          Peter

                          1 person found this helpful
                          • 10. Re: Progress bar does not update help
                            miguel8312 Level 3

                            thanks for all your help pete i guess this is not doable  with a loop. I guess the progress bar was just not meant to be used in this fashion. I'll have to rethink what to do until the datagrid is full with data.

                            Thanks

                            Miguel

                            • 11. Re: Progress bar does not update help
                              Peter deHaan Level 4

                              I'm certain that it is quite do-able, I'm just using various timers to simulate having actual data...

                              The following example uses a timer to add a new record to a DataGrid control every 100ms. Then whenever the code adds a new record to the ArrayCollection (which is bound to the DataGrid control's data provider), I update the ProgressBar accordingly. After all 200 records have been added to the data provider (takes around 20 seconds), I hide the ProgressBar.

                               

                              I'm just wondering if maybe you're setting the progress bar with an incorrect current/total value).

                               

                              <?xml version="1.0" encoding="utf-8"?>
                              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();">
                                  
                                  <mx:Script>
                                      <![CDATA[
                                          private var timer:Timer = new Timer(100 /* ms */,
                                                                              200 /* iterations */);
                                          
                                          private function init():void {
                                              timer.addEventListener(TimerEvent.TIMER, timer_timer);
                                              timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_timerComplete);
                                              timer.start();
                                          }
                                           
                                          private function timer_timer(evt:TimerEvent):void {
                                              var obj:Object = {c1:'Column 1', c2:'Row ' + timer.currentCount};
                                              arrColl.addItem(obj);
                                              
                                              pbProgress.setProgress(timer.currentCount, timer.repeatCount);
                                          }
                                          
                                          private function timer_timerComplete(evt:TimerEvent):void {
                                              pbProgress.visible = false;
                                              pbProgress.includeInLayout = false;
                                          }
                                      ]]>
                                  </mx:Script>
                                  
                                  <mx:ArrayCollection id="arrColl" />
                                  
                                  <mx:Panel>
                                      <mx:DataGrid id="dg" dataProvider="{arrColl}" width="300" />
                                      <mx:ControlBar>
                                          <mx:ProgressBar id="pbProgress" mode="manual" label="%1 of %2 records added (%3%%)" labelPlacement="center" width="100%" height="40" />
                                      </mx:ControlBar>
                                  </mx:Panel>
                                  
                              </mx:Application>
                               
                               
                              
                              • 12. Re: Progress bar does not update help
                                miguel8312 Level 3

                                I dont think im using the incorrect parameters on the  processbar but i guess I might be. I mean here it is.

                                 

                                pbProgress.setProgress(i,record.length);

                                 

                                 

                                this is like you suggested earlier. i think is a question of where do i need to have this? im looping throught a bytearray and then push the arrary to the datagrid... i think your example is closer to what i need yet im struggling on making it fit to my needs. however im very greatful for all  your help. In VB I've been able to do this very simple but i guess my ignorance in flex is making my life a little harder :-) thanks for all your help pete.

                                Miguel