I'm documenting this here for others who may be struggling with this:
It has been suggested to use a VBox and simply just add children to
it based on items in the dataprovider. That's a great approach and
would have been my workaround. However, Alex was giving enough
pointers to implement the solution based on storing the expanded and
collapsed state in the data object.
This can be easily done by overriding the data property of the item
renderer and using a 'collapsed' property to restore the state of the
item renderer.
So, here is an example:
override public function set data(value:Object):void {
super.data = value;
if (value.collapsed) {
currentState = "Closed";
} else {
currentState = "Open";
}
// Dispatch the dataChange event.
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
Use the following to switch the state:
private function switchOpenState():void {
if (currentState == "Closed") {
currentState = "Open";
data.collapsed = false;
} else {
currentState = "Closed";
data.collapsed = true;
}
}
I'm working with states and transitions, but this can be used in
other ways as well. The other piece would be to use a function to
switch the collapsed state and then setting the data.collapsed
property. Changing the state causes a sequence of events that will
eventually evaluate the data.collapsed property of each item renderer
and restore it to its proper state should the user scroll through the
list or interact with it in any other way.
Hope this helps,
Jurgen
On Oct 18, 2007, at 1:47 PM, Alex Harui wrote:
Renderers are recycled. Only as many renderers that you can see
are created regardless of how many items in your data provider.
So, one renderer can end up having to render various items in the
dataprovider. As such, all aspects of its visuals must be driven
by the .data object including which state it is in.
From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of Jurgen Beck
Sent: Thursday, October 18, 2007 11:14 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] List Component: Working with Collapsed and
Expanded ItemRenderer
I am experiencing something mildly strange with the List component
when using a custom item renderer that has two states, a collapsed
state and an expanded state.
When I have one or more item renderers in the expanded state, the
List component eventually will display the vertical scrollbar. Here
is the strange part:
When using the scrollbar to scroll through the list, the original
expanded item renderers that would normally disappear with their
expanded state from the visual range of the list get collapsed and
new list items that have not been expanded do so in their place.
As I am not forcing this behavior my thinking is that the List
component is either missing a property setting to prevent this
behavior, or this may be either a bug, or simply by design.
Anyone with some more info on this?
Thanks,
Jurgen