3 Replies Latest reply on Nov 25, 2010 9:05 AM by MichaelBolten

    ItemRenderer with Loader

    MichaelBolten

      Hi,

       

      i have a s:list filled by webservice. I use a ListItemRenderer to show images in this list.

       

      In the oncreationcomplete event of the renderer i create a loader to load an image.

       

      Everything is ok.

       

      Now i need to clear the list by using list.dataProvider.removeAll() .

       

      The list ist cleared and i want to fill the list again with different images, so i call the webservice. The list is getting filled again but with wrong images.

       

      The problem ist, the Itemrenderer creationcomplete event is not fired cause of the ItemRenderers are still alive.

       

      I have used the profile to check what happens.

       

      after the first call to fill the list i have 40 itemrenderers. after removeAll() i still have 40 itemrenderers.

       

      Now i fill the list with 60 images, i have 60 itemrenderers.

       

      How can i remove all the unneeded itemrenderers ?

       

      Thanks

       

      Michael

        • 1. Re: ItemRenderer with Loader
          BhaskerChari Level 4

          Hi Michael,

           

          Itemrenderers get recycled and the creationComplete in Itemrenderers is fired only once as they are not created again but recycled.

           

          So you shouldn't load your images in creationComplete event instead override the set data function which is called for each itemRenderer when ever your dataProvider changes and in this function you can load images by creating a loader.

           

          So in your itemRenderer override the set data() function as shown below..

           

          override public function set data(value:Object):void

          {

               var loader:Loader = new Loader();

               loader.url = someurl;

               loader.load();

          }

           

           

          Thanks,

          Bhasker

          • 2. Re: ItemRenderer with Loader
            MichaelBolten Level 1

            Hi Bhasker,

             

            thank you for your help.

             

            one thing is a bit disturbing me, when the list is getting filled, first i see the wrong pictures. after a while, the loader has comleted, the image is shown correctly.

             

            How can i clean the image before loading the new ?

             

            Thanks

             

            Michael

            • 3. Re: ItemRenderer with Loader
              MichaelBolten Level 1

              Hi,

               

              i got it.

               

               

               

              if ( ( super.data == null ) || ( super.data.internalid != value.internalid ) )

              {

                   im_thubm.source = null;

              }

               

              in the set data i check wether the data is not null, never set, i set the image source to null to clear the image.

               

              Thanks alot

               

              Bye Michael