0
votes

Is it a bad idea to inject data into an itemrenderer. The reason I ask this is because the state of each item is dependent on different changing data sources. So the original data is used to just display a new item, but there could be two to three other data collections that would be needed to determine the item's behavior. Is there a better way to do this? Should I be creating a custom DataGroup with the other data sources as properties on this custom container and then reference the data sources from the itemrenderer to the parent?

Also, I'm using swiz if this matters or helps at all.

1
To answer your first question - yes. It's always a bad idea to inject data into itemrenderers. Flex only creates itemrenderers for the number of items in the viewable area (+ a couple for a buffer) and so they are recycled. This recycling means that injecting into itemrenderers is bad.Sam DeHaan

1 Answers

1
votes

Indeed, it's generally not a good idea, it's much better to set the data property of the renderer, and just make sure that the data contains everything the renderer needs.

If the renderer needs information from other data collections, just set the item's data before assigning it to renderer.

The way, I see it should be like that:

Controller
- Data collection 1
- Data collection 2
- Data collection 3

First, the controller gathers data from the three data collection, and creates some data D based on them

Finally the controller assigns this data D to the renderer. That way the renderer has no dependency to other external data collection.