Flex/AS3 Using Multiple Item Renderers In a List
I'm trying to have multiple item renderers in a list, as I have several different types of objects that I want to display. I tried creating a new class that extends ListBase, and adding override public function createItemRenderer with my code within this function. I then instantiate the new class and give it my array of data as its dataProvider, but createItemRenderer is never called within my new class, can anyone help me please?
Thank you
I managed to solve this by extending List instead of ListBase, so thanks shakakai for making me think about that :)
Incase anyone else has a similar problem here is what my code looks like:
public class MultipleRenderersList extends List
{
override public function createItemRenderer(data:Object):IListItemRenderer
{
if (data is Type1)
{
return new Type1Component;
}
else if (data is Type2)
{
return new Type2Component;
}
return null;
}
I've dealt with this in the past by creating a single item renderer that can handle different types of data. There are a few ways to do this, such as changing states based on data type, or using a ViewStack that switches based on data type, or using actionscript to create/add a sub-component to display the data appropriately. Just override the set data method on your item renderer and switch up the components as necessary. Hope that helps.
链接地址: http://www.djcxy.com/p/5912.html上一篇: 如何避免在项目渲染器中加载“if语句”