0

I have a spark list with custom Itemrenderer. I use virtuallayout , because I'm binding it with about 500 elements.

I traced the datachange event of the item renderer and I've seen that about 120 items are binded to the list on the first load. I need to show only 10 items on the stage, so I want to decrease the number of items fetched in the list, is there a property or a function to override to obtain this behaviour?

The code is so simple

<s:List  id="thumbnailList" verticalScrollPolicy="off" 

 useVirtualLayout="true" itemRenderer="ThumbnailItemRenderer" >
        <s:layout>
            <s:HorizontalLayout gap="10"  requestedColumnCount="10"  />
        </s:layout>
    </s:List>

The item renderer

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark"
                    autoDrawBackground="false"  >
    <fx:Script>



            override public function set data(value:Object):void{
                super.data=value;
                if(data !=null){
                    LoadImg();

                }
            }


            protected function LoadImg():void{
                trace(data.pagnum.toString());
                var cacheDir:File=null;
                cacheDir= Config.DirCache();
                var folder:File = new File(cacheDir.nativePath + Config.CATALOG_FOLDER_NAME + Config.selected_catalog_id + "/");                    
                var file:File = new File(folder.nativePath + "/" + data.pagnum.toString() + "_th.jpg"); 
                trace(file.url);
                thumbnail.source = file.url;

                cacheDir=null;
                folder=null;
                file=null;

            }



    </fx:Script>


    <s:Image id="thumbnail" top="0" left="0" right="0" bottom="0" scaleMode="letterbox" cacheAsBitmap="true"  />
</s:ItemRenderer>

and the binding of the list

thumbnailList.dataProvider= {ArrayCollection with about 480 items}
zero323
  • 322,348
  • 103
  • 959
  • 935
Luca V
  • 26
  • 6
  • Instead of using Binding, override the `set data` method of your `ItemRenderer`. – AlBirdie Jul 05 '12 at 07:32
  • Yes it's done. The point is another: we know how virtual layout works. You bind the elements (set the datasource) and it shows only the visible elements on the stage. When you set the datasource it's easy to trace something in the set data overridden function and see how may items are binded. In my case 128 items are binded but only 10 are visible on the stage. I want to reduce the number of items binded – Luca V Jul 05 '12 at 07:57
  • Are you certain it's 128 discrete items and not the trace being executed 128 times on the same items, say 10 * 12? – RIAstar Jul 05 '12 at 08:43
  • I'm sure, because every istance of itemerender show a different thumbnail, I trace the source of the thumbnail and it's different every trace – Luca V Jul 05 '12 at 09:41
  • You actually don't need to set `useVirtualLayout` to true as it's true by default. Anyway, you should only see about 12 traces when 10 items are visible in the list. Have you tried a simple trace on the data in the `set data` method? How often does that fire? – AlBirdie Jul 05 '12 at 10:51
  • Yes, I traced the set data method. When i set the datasource of the list it's fired 128 times..this is the real problem, it makes slow the loading of the list. – Luca V Jul 05 '12 at 12:04

0 Answers0