views:

449

answers:

1

I've added an eventListener to the COLLECTION_CHANGE event that is fired when the grid is finished resorting the items in its dataProvider, after the user clicks on a column header:

    MyType (myDataGrid.dataProvider).addEventListener(CollectionEvent.COLLECTION_CHANGE,
 onDataGridResort);

...

    private function onDataGridResort(e:CollectionEvent) : void {


    }

MyDataGrid has some custom helper methods for working with the dataProvider and it would be useful to have access to them from inside the onDataGridResort function. Can I get access to the datagrid to which the dataProvider has been attached? When I examine "e" (CollectionEvent) in the debugger, I see

[inherited]
   currentTarget
      listeners
         [0]
         [1]
         [2]
             savedThis    MyDataGrid

It seems an unreliable way to get at the grid component from inside this eventhandler -- will the grid always be found at property savedThis at offset [2] in the listeners array beneath currentTarget?

+1  A: 

Relying on the currentTarget.listeners property is very unreliable. The problem with accessing the grid from the event listener is that the dataProvider broadcasts the event, not the grid. So there really is no relationship between the event and the grid.

In the example above, it appears you could access the grid directly with myDataGrid. If that is not the case in your real app, then you need to create a wrapper class that contains a reference to MyDataGrid and onDataGridResort the grid can be referenced from the event handler.

Sam