views:

74

answers:

2

How to access List itemRenderer and its properties (Spark - Flex 4)? I want to iterate through list and do something like (note it's pseudo code):

for (var i=0;i<NUMBER_OF_ITEMS_IN_LIST; i++){
  myList.getItemRenderer[i].property
}
+1  A: 

What type of processing do you want to perform on the renderers? I suspect a loop like that will not give you what you need.

Renderers are only created for the elements that you see on the screen. There will not be a renderer for every item in your dataProvider. This is done for performance issue. You should be able to access the List renderers through some property in the API, but it may not be public, or documented. I took a quick look and couldn't tell.

In the Halo ListBase, there are protected properties named reservedItemRenderers and freeItemRenderers properties. I assume they must be something similar in the Spark List.

www.Flextras.com
You are right, renderers are just for visible items and I can't do what I wanted. The only way to do what I wanted is to access dataprovider of list instead of itemrenderers.
dede
A: 

Hi,

Iterating over ItemRenderers in Spark is easy. Just loop over the elements in list.dataGroup and you're good.

if (list && list.dataGroup) {
 var i:int, numItems:int = list.dataGroup.numElements;
 for(i= 0;i < numItems; i++){
  var itemRendererItem:IItemRenderer = list.dataGroup.getElementAt(i) as IItemRenderer;
 } 
}
JoriDor