I'm trying to cycle through my list itemRenderers to change the data of a particular item. The code runs well until the for index becomes 7 (which is the maximum number of visible elements on my list). When the index is 7 or more, the getElementAt() function returns null. What could possibly be the problem?
var itemRenderer:ItemRenderer;
var numItems:int = list.dataGroup.numElements;
trace(numElements) // outputs 14
for(var i:int = 0; i < numItems; i++){
itemRenderer = list.dataGroup.getElementAt(i) as ItemRenderer;
if (itemRenderer.data.name == "bar") {
itemRenderer.data.option = "foo";
break;
}
}
If you want to change the data of a particular item, why not change it from the data you gave to the dataProvider
? Changing it directly in the item renderer is ludicrous.
And for future reference, the reason why that fails is because of something called virtualization. Essentially, not all item renderers are created, only the ones visible.