iman453
iman453

Reputation: 9575

Event once all the custom item renderers have been created/set

I'm using a custom item renderer in my datagrid, and need to make a button visible or invisible based on if there has been a negative value on any of the values in the renderer. So I'd like to set a flag to false when the first renderer is set off, turn it to true if there's any negative values, and at the end check for the value of the flag. I know I can dispatch a dataChange event for every time the data is changed in the renderer instances, but I was wondering if there is anyway I can know when all of them are done? Thanks!

Upvotes: 1

Views: 253

Answers (2)

robmcm
robmcm

Reputation: 891

You should have a look into RendererExistenceEvents. You should be able to tell when they are all created based on how many items you have in your list or at least how many should be in view at once.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/events/RendererExistenceEvent.html

Upvotes: 1

Sunil D.
Sunil D.

Reputation: 18193

There is no such event.

Like any other Flex component, a renderer will dispatch a CREATION_COMPLETE after it's been created. ItemRenderers are generally recycled (the same object gets assigned new data to render), thus listening for CREATION_COMPLETE is not sufficient, unless you disable the recycling.

For a Spark List component, you can disable recycling by setting useVirtualLayout=false on the layout class. I'm not sure if the Spark DataGrid class support this or not. The MX DataGrid may have some other way to do this.

Disabling the recycling, however, can have performance implications. I think your idea w/the DATA_CHANGE event is the best solution:

  • determine the initial state of the data (ie: are there any negative values)
  • in the renderer, use the DATA_CHANGE event (or just override the setter for the renderer's data property) to know when the data has changed
  • When the data changes, dispatch a custom event class that will bubble. This event has a property that tells you if the value is negative or not.
  • Since your custom event from the renderers will bubble up to the grid, you can add one listener on the grid to handle changes from all the renderers.

Upvotes: 2

Related Questions