FlashComGuru Home Imediasee Influxis Uvault Akamai
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (8)
Applications (32)
Books & Training (9)
Collaboration (8)
Components (6)
Events (49)
Flash Player (8)
Flex (28)
FMS (67)
General (107)
Hosting (5)
Jobs (13)
Off topic (31)
Press Releases (7)
Site Check (7)
Tools (39)
Videos & Players (50)

Flash On the Beach

Alltop, all the cool kids (and me)

 
Here's a little Flex component (I called it ExpandingList) that may come in handy when you want to build a people list in Flex - just like I just did. This List allows each item to be doubleclicked and expanded, revealing more info, in this case on a particular user. Another doubleclick closes the item again. The functionality is achieved by using an itemRenderer.
Many thanks to Tink who helped me along the way by suggesting I use mx:Resize and Mike who gave me some tips on the doubleclicking. Well done team :-)

There is however a bug that I can see. When you expand one item and then scroll up and down in the list quickly the items are mixed up, or shuffled around. At least it seems that way as suddenly the expanded item may be at the bottom instead of the top for example. I think I know that this has to do with the way that List items are recycled by Flex but how can I avoid this happening? Any other improvements I could make?

Sample is here, source here.

UPDATE: thanks Mike for submitting one possible fix. Check it here.

Comments
[Add Comment]
i get another bug: when expanded last element is often cut. (though scrollbar do redraw on expansion...)
# Posted By laurent | 3/16/07 11:49 AM
He Stefan, I've send you the new(second ;)) fix.
# Posted By Maikel Sibbald | 3/16/07 1:13 PM
That is really *horrible*!
# Posted By Pablo Fabreze | 3/16/07 1:37 PM
...says Pablo, who doesn't like to share his website address but who has most likely coded itemRenderers in Flex since 1995.
# Posted By Stefan | 3/16/07 1:54 PM
I am waiting for a flight, so this is off the top of my head. Two approaches, keep the doubleClicked state on the data object not the itemRenderer. Second approach is to tell the List not to recycle its children. The first works but might not be what you want in your data, but a variation would be to keep the state outside the itemRenderer relative to the actual data objects and not the recycle'd itemRenderers.
# Posted By Renaun Erickson | 3/16/07 2:05 PM
thanks Renaun,
we kind of decided against the data as a storage for the expanded state as it interferes with the dataprovider. Worst case: you may override a property of the actual dataprovider.
The second one was my first idea - but list doesn't seem to have a recycleChildren property. Or did I miss this?
# Posted By Stefan | 3/16/07 3:01 PM
Stefan, are you going from FMS guru to FlexGuru :-) That's great for all of us because you've been the best (from my view) with FMS!

thank again from this side of the 'lantic

Tom
# Posted By Tom Sammons | 3/17/07 12:00 AM
hey Tom,
I'm blushing :-)

I wouldn't say from FMS to Flex but from FMS without Flex to FMS with Flex. The two make a great team - I'll post some links once this chat app is finished. Itemrenderers rock btw :-)
# Posted By Stefan | 3/17/07 7:53 PM
The flex list component has major issues when it comes to item renderers...it starts breaking, as you saw
# Posted By Eric | 3/19/07 8:57 AM
Flex its great component, thanks
# Posted By Pioneer | 10/4/07 10:08 AM
Stefan, care to elaborate on that one possible fix you posted? I am seeing this bug too and I don't have any elegant solution so far.
# Posted By William Khoe | 10/8/07 2:56 AM
hi William,
does the fix posted above not work for you? Do you have any specific questions?
# Posted By Stefan | 10/8/07 9:42 AM
Yeah, it works for me. After reading the source code, I think I get it now, the item renderer is just a placeholder and is not able to store any state since it get recycled, so you store the state externally...in this case, in List itself. It can also be done in the data, but I guess that would pollute it. Either way, not a nice solution, I hope future releases could provide something better.

Btw, you should complete your blog post by explaining what the fix is. It confuses lazy people like who don't bother to read comments or source :)
# Posted By William Khoe | 10/9/07 4:27 AM
Hi,

This works fine but only if the elements in the list have a fix height, if you use a variable height the bug appears again...in your case if you have more info about a particular user you have to use a variable height, so the information appear correctly...
I have to create a list that uses itemRenderer and the list elements have a variable height but I can't resolve the scroll bar issues....can anybody help me?:)
# Posted By Ramona | 1/31/08 1:41 PM
Stefan, are you going from FMS guru to FlexGuru :-) That's great for all of us because you've been the best (from my view) with FMS!

thank again from this side of the 'lantic

Oyun
# Posted By Oyun | 2/11/08 12:08 AM
I have to create a list that uses itemRenderer and the list elements have a variable height but I can't resolve the scroll bar issues....can anybody help me?:)
# Posted By kale kasa | 2/18/08 11:00 AM
I have to create a list that uses itemRenderer and the list elements have a variable height but I can't resolve the scroll bar issues....can anybody help me?
# Posted By kale kasa | 4/7/08 1:31 PM
Another solution how to remember the expanded state:
Use a static array in the item renderer. This way you keep
information in the item renderer only without touching any
other component.

// declare the static array
private static var expandedItems:Array = new Array();

// In the setter function of the item renderer where you
// set the data object, set the size quickly and directly.
if( expandedItems.indexOf(data)>-1 ){
   // show this item in expand size without an effect
} else {
   // show this item in contract size
}


//In the function where you expand and collapse
//the item renderer on double click, play the expand
//or contract effect and remember
//the size in our static array:

private function setRowSize():void{
var arrayPosition:int = expandedItems.indexOf(data);
if( arrayPosition>-1 ){
contract.end();
contract.play();
expandedItems.splice(arrayPosition,1);
} else {
expand.end();
expand.play();
expandedItems.push( data );
}
}
# Posted By Rainer | 4/23/08 10:56 PM
Hmmm... I would love to read an update and see if any of these suggested fixes actually worked? You should update your post.
I have managed to find another solution of my own though, but I'm wondering if yours won't simply be a lot cleaner than the other one I'm currently using. Provided this issue can be sorted out, of course.
# Posted By jewellery | 7/10/08 1:22 PM
The flex list component has major issues when it comes to item renderers...it starts breaking, as you saw
# Posted By Oyun | 7/22/08 6:40 AM