views:

24

answers:

1

In Flex I can create an ItemRenderer to represent each item in the Lists DataProvider but how do I access the instance of the ItemRenderer via the DataProviders Object? Something like myList.getItemRenderer(dp.getItemAt(10));

A: 
public function getItemRenderer(list:List, item:Object):ItemRenderer
{
    var dataGroup:DataGroup = list.dataGroup;
    var n:int = dataGroup.numElements;
    for (var i:int = 0; i < n; i++)
    {
        var renderer:ItemRenderer = dataGroup.getElementAt(i) as ItemRenderer;
        if (renderer && renderer.data == item)
            return renderer;
    }
}
Maxim Kachurovskiy