6 Replies Latest reply on Feb 17, 2011 4:47 AM by Stewar2402

    Stop loading images from Web Service


      Using the following code I put multiple request for images to the web service:


                          var pageArray:ArrayCollection = new ArrayCollection;
                          pageArray = event.result as ArrayCollection;


                          for (var ii:int = 0; ii < pageArray.length; ii++)
                              var filePage:FilePage = (filePages.placeImagesHere.addElement(new FilePage) as FilePage);


      The loading takes place as multiple images are returned fom the server. All is well until the user wants to abort the image loading to view something else. removeAllElements() is called when a Close button is pressed but the images are still returned in the background.




      If many images are to be returned the user has to wait for this to finish before the next lot of images can be viewed. I would have expected the function removeAllElements() would stop the process but it doesn't.


      Is there any was to 'flush' or stop all previous image requests?




        • 1. Re: Stop loading images from Web Service
          miguel8312 Level 3

          webservice calls from flex are asynchronous. therefore im not sure what problem are you having you are users should still be able to move around your site. you can also put a timer in your application and then just load images sequentially in the order you preffer.

          look at the using something like this.

          public var timer:Timer = new Timer(10)
          • 2. Re: Stop loading images from Web Service
            Stewar2402 Level 1

            Thanks for the reply but the for loop finishes and the asynchronous event of receiving the images still occurs.


            For example, the for loop loads 500 images. The web service takes 2 or 3 mintues to process all the images and returns them into each requesting Image component. The Close button calls the removeAllElements from the Images' parent so they no longer appear on the screen. However, the browser is still receiving the images. You can see the transfering data message flick on and off in the status line al the bottom of the browser.


            The web service hasn't received all the requests at this point so they are still in transit from the browser to the web service.


            Using a timer to load the images just means the images requests take longer to send to the web service.


            What I need to do is cancel all image load requests when the user presses the Close button.


            Hope this make sense.



            • 3. Re: Stop loading images from Web Service
              miguel8312 Level 3

              i guess you can put a condition to run the result handler function that handles the service. In other words put a boolean value in your code and set it to true when you want to  stop passing images to the arraycollection depending on your predefined condition.  so when the user pressess the close button set the variable to false which will then not allow result handler to load more images. basically skipping loading images.

              hope this make sense



              Message was edited by: miguel8312

              • 4. Re: Stop loading images from Web Service
                Stewar2402 Level 1

                Sorry Miguel, I don't think you quite understand the issue. Its not the result handler that is receiving the images it is the Image component - which no longer exists on the stage.

                • 5. Re: Stop loading images from Web Service
                  miguel8312 Level 3


                  you have an image component that is getting the image from a webservice? Right? If the answer to this is yes the webservice call is going to bring back all the images as long as their images to be retrieved. How do the images get assign to the component? no result handler?  I guess i m just confused you prob need to post some source that would be more helpful.


                  • 6. Re: Stop loading images from Web Service
                    Stewar2402 Level 1




                    Hi Miguel, many thanks for help so far. I believe I has resolved my problem. The event handler was the key to it. I was loading all the images simultaneously by requesting them with the load function of the Image components. I've changed this to add the Complete event on each image and load one image at a time as the previous one completes. If the user presses Close (stop) then the requests stop. It is slower because I have to wait for each image to complete the load process but it means I have more control.