i use a flex spark itemrenderer to visualize rows of data. each row also has a button that should do something dependening on which row it is. for this i need access to the datarow when the button is clicked. but i dont know how to get it.
this is how the itemrenderer looks:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">
<fx:Script>
<![CDATA[
private function click(e:flash.events.Event):void
{
//how do i get access to the data of the row here?
}
]]>
</fx:Script>
<s:HGroup>
<s:Label text="{data.GameName}" width="300" />
<s:Button label="Start" click="click(event)" />
</s:HGroup>
</s:ItemRenderer>
The data property of the itemRenderer will contain the element from your dataProvider that this itemRenderer is currently displaying.
You can use use the itemIndex property to get the index of your data element inside the list’s dataProvider.
I think you need one of the previous two, but since “datarow” is ambigious to me, here are a few other thoughts that may help.
If you need to access the instance of the row; that is no different than the itemRenderer instance, so you can use the
thiskeyword to access properties on the itemRenderer where the button was clicked.If you need to know the index of the itemRenderer in the context of all of the list’s itemRenderers; that is going to be much more difficult. Since itemRenderers are reused as the list is scrolled, there is not a one-to-one relation between the number of renderer instances and the number of items in your dataProvider. I’m not sure why you’d need that, though, so I’m guessing this is not what you need.