views:

66

answers:

2

How do I differentiate between a data provider update and a itemrender being recycled when using a custom itemrenderer in a DataGroup?

I have overridden the set data function of the custom item renderer, but I have found that on making a change to the ArrayCollection used as the DataProvider some of the item renderers are not assigned the same object they had before the update. This has made it almost impossible for me to distinguish between a data update and an itemrender being recycled. Also, the data never seems to get set to a value = null, so that seems to be out as well.

Any ideas?

+1  A: 

I'm not sure what your asking exactly.

Renderer recycling is the process of changing a renderer's data, often as you scroll through a list based class. This is for performance reasons, so that only items displayed on scree are renderered, not items displayed off screen. Renderer recycling is used to simulate scrolling through a list w/o actually doing so.

When you replace the dataProvider it update all renderers. When you change the dataProvider, it may update some renderers, depending on what the change is. I have gone through the dataGroup code, so I'm not sure exactly what it does for updates, but the Halo listBased classes implementa collectionChange event handler to handle these changes. I would suspect a DataGroup does something similar.

Why do you need to know the reason a renderer's data was changed? The renderer should only care that it was changed.

www.Flextras.com
+1 for the last line!
Amarghosh
I have a windowshade component as part of an item renderer. If the data is updated because of the data in the arraycollection changing I would like to leave the window open. If it is changed because of a recycle of the component (an open shade rolling off the top, and to the bottom) then I would like the shade to come up as closed.
rosswil
@Amarghosh Thanks for the Karma. @rosswil You might be able to work something out by listening to the collectionChange event of the parent, but it would be a bit messy and would break encapsulation.
www.Flextras.com
A: 

There is a dataChange event that bubbles up when their is a change to the {data} provider.

<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/mx" 
                autoDrawBackground="true" width="142" height="22" dataChange="WHATEVERYOUWANT"
Craig Mc
but this event also gets fired when data is changed in the itemrender due to it being recycled.
rosswil
The other option is if you only wish to have this happen at inception of the component/renderer is to use: creationComplete
Craig Mc
The other option is if you only wish to have this happen at inception of the component/renderer is to use: creationCompleteI have a complex set of multi function, controls that I have made an itemRenderer, creationComplete is what I used as a compramise, because 1) it happens only once. 2) it happens after the data event, 3) controls are ready to recieve changes, I found sometimes dropdownlists were not ready when the datachange fired.
Craig Mc