10 Replies Latest reply on Mar 8, 2010 12:13 PM by Flex harUI

    Progress Status Not Polling

    alice_data Level 1

      Hi,

       

      I have the code as in the following,


        public function changeMap():void{                        
           
              var from_string:String = from.join("-");
              var state_colors_string:String = stateColors.join("-");                  
                    
              var loader:URLLoader = new URLLoader();
              var url:String = "http://localhost/generic.php?from=" + from_string + "&state_colors=" + state_colors_string;
              var variables:URLVariables = new URLVariables();
                  variables.from= from_string;
                  variables.state_colors = state_colors_string;
              var encode:String= encodeURI(url);
              var pattern:RegExp = /#/g;
              var decode:String = encode.replace(pattern,"%23");
              var request:URLRequest = new URLRequest(decode);
              request.method = "GET";
              loader.load(request);       
              loader.addEventListener(ProgressEvent.PROGRESS,_onProgress);     
               pb= new ProgressBar();
               pb.move(10,10);
                pb.mode = ProgressBarMode.POLLED;
                       pb.direction = "horizontal";                      
                       horizontal_bar.addChild(pb);
               loader.addEventListener(Event.COMPLETE, onLoadComplete);    
              }       
              private function _onProgress(e:ProgressEvent):void {       
                           
                             if(e.bytesLoaded == e.bytesTotal) trace( Math.floor(e.bytesLoaded/1024) + "KB" );
                             else trace("Not loaded yet" + Math.floor(e.bytesLoaded/1024) + "KB");
                     }
              public function onLoadComplete(event:Event):void {               
                      horizontal_bar.removeAllChildren();       
                       
              }       
          }

       

      However, the "loading status" only stays on 0 when I would like it to be polled. Looks like according to http://livedocs.adobe.com/flex/3/html/help.html?content=controls_20.html, I may need to add the source, but which is the source that I should use?

       

      Thanks for your help.

        • 1. Re: Progress Status Not Polling
          Karl_Sigiscar_1971 Level 3

          The source property must be set to any instance of a class that dispatches COMPLETE, PROGRESS... events and has the bytesloaded and bytestotal properties (or one of its superclasses defines these properties and dispatches these events).

           

          FileReference and Image are two examples of such classes.

          • 2. Re: Progress Status Not Polling
            alice_data Level 1

            I tried running the trace statements, and it runs all the way to 1820KB as the ebytesLoaded. Yet, when this number is in the trace statement, there are still 6 or 7 seconds before the "image" shows up here

             

            Since my progressBar is not polling like it should, according to my code, would my source be "request" as in

             

                var request:URLRequest = new URLRequest(decode);
                    request.method = "GET";

             

            from my code?


            Thanks for your help.

            • 3. Re: Progress Status Not Polling
              Karl_Sigiscar_1971 Level 3

              Your source would be loader in that case.

              • 4. Re: Progress Status Not Polling
                alice_data Level 1

                Thanks, I now have pb.source= loader in my code like you suggested. However, when I load it,

                the progressBar shows on the screen, it says "Loading 0%" and then vanishes when the image finally shows up. Am I not supposed to see something like Loading 20% incrementally until the image appears?

                 

                Why is my progressBar still not polling?

                Does this make any sense of what I am describing here?

                 

                Thanks for your help.

                • 5. Re: Progress Status Not Polling
                  Karl_Sigiscar_1971 Level 3

                  You should have pb.source = loader, not pb.source(loader)

                  • 6. Re: Progress Status Not Polling
                    alice_data Level 1

                    I just changed that.

                     

                    However, the progressBar says "Loading 0%" and then vanishes when the image finally shows up. Am I not supposed to see something like Loading 20% incrementally until the image appears?

                     

                    Why is my progressBar still not polling?

                    Have I made other mistakes here that I may not be aware of?

                     

                    Thanks for your help.

                    • 7. Re: Progress Status Not Polling
                      Karl_Sigiscar_1971 Level 3


                      I don't know what's wrong with your code. But to achieve what you want, I would use MXML:

                       

                       

                       

                         
                          <mx:Image id="image"
                              width="100%"
                              height="100%"
                             completeEffect="Fade"

                             source="{imageURL}">
                          </mx:Image>

                       

                          <mx:ProgressBar
                              showEffect="Fade"
                              hideEffect="Fade"
                              themeColor="0xFF0000"
                              horizontalCenter="0"
                              verticalCenter="0"
                              fontSize="12"
                              styleName="ApplicationFontStyle"
                              label="Downloading image..."
                              source="{image}">

                          </mx:ProgressBar>

                       

                      The Image class extends SWFLoader, so you don't have to bother with complicated Loader code in ActionScript.

                      • 8. Re: Progress Status Not Polling
                        alice_data Level 1

                        Hi,

                         

                        As a matter of fact, I saw something like that in the Flex manual, and since in my case most of the items are built dynamically through Actionscript, I probably cannot use this.

                         

                        For my polling problem, I am still not sure why my code does not have anything other than 0% when I run it, even though this child does get deleted correctly when the image does show up.

                         

                        I think I will give it a shot and see what the Actionscript people say about this. I will probably come back and let you know if I find anything else.

                         

                        Thanks though.

                         

                        Alice

                        • 9. Re: Progress Status Not Polling
                          alice_data Level 1

                          Well, I found a way to get around my problem, and that is to change the source attribute to indeterminate. Since I don't know the dynamic size of how big my image is, I set indeterminate to true.

                           

                          This seems to be working now. Yet, if anyone can think of a better solution, please feel free to provide them.

                          Thanks.

                          • 10. Re: Progress Status Not Polling
                            Flex harUI Adobe Employee

                            Normally to watch a Loader you use EVENT, not POLLED.  If you are seeing a

                            delay after bytes are loaded, that will be because the data has to be

                            converted.   You would need a pseudo-thread in order to show progress during

                            data conversion.