views:

32

answers:

2

I have a Flex list and a custom ItemRenderer. I'd like to be able to have some items in the list use a different ItemRenderer (say, depending on the class of the item). Is this possible?

E.g.:

<s:List dataProvider="{_systems}" itemRenderer="myItemRenderer"/>

Most items in _systems use myItemRenderer. But if element 3 of _systems is "specialSystem" the renderer would be "specialItemRenderer".

Is this possible?

+1  A: 

You use Canvas as ItemRenderer and implement mechanism which will create other controls automatically.

More details you can find in this article: Different Items renderers in List

The main idea:

You create special ItemRenderer which can create "emulate" other controls, in our case it is subclass of Canvas which simply creates and adds desired control. Then we need some mechanism to tell our container which renderer we want to emulate, for this purpose we use ItemContainerData with special fields.

DixonD
That would be the only approach for Flex 3, Halo lists. But Flex 4 introduced the itemRendererFunction which will provide a much cleaner implementation.
www.Flextras.com
+2  A: 

Use an itemRendererFunction.

Here is a blog post tutorial on that. I also touch on this here.

www.Flextras.com
That appears to be exactly what I'm looking for, thanks!
justkevin