0
votes

I'm making a Custom ItemRenderer in Flex which is for a DataGrid. My problem is, I need to be able to use listData so I can figure out what the current row the ItemRenderer is in. I Can't seem to implement IDropInListItemRenderer correctly though, because no matter what listData is always null for me.

Here's my code at the top:

<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" autoDrawBackground="false" styleName="gRenderer" dataChange="setStates()" implements=" mx.controls.listClasses.IDropInListItemRenderer">

And then I have:

 private var _listData:BaseListData;

And then I have:

public function get listData():BaseListData {
        return this._listData;
    }

    public function set listData( value:BaseListData ):void {
        this._listData = value;
    }

But then in my set data method I try to do this:

 override public function set data( value:Object ):void {
        super.data = value;
       var row : int = listData.rowIndex;
    }

But at run time it throws an error saying it's trying to access a property of a null object. In my debugger, I can see that listData is null. I can't figure out why. From what I've read everywhere online it seems like I'm doing everything needed. What am I missing?

Thanks!

1
Are you dealing with a Spark DataGrid or an MXDataGrid? Using a Spark ItemRenderer in the MXDataGrid should use DataGridListData help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/… not listData. - JeffryHouser

1 Answers

0
votes

It looks like you are building a custom ItemRenderer for a spark datagrid. If so, instead of using the base class s:ItemRenderer use s:GridItemRenderer. There is a public property of rowIndex that you can reference.

override public function set data( value:Object ):void {
    super.data = value;
    trace(rowIndex);
}