I need change itemRender on fly for List. New itemRenderer will work properly.
use [YourList].itemRenderer=new ClassFactory(getDefinitionByName([your new item renderer class name]) as Class);
I show just few hint because other code is trivial.
So lets suggest we have few itemRenderer's : Complex,Simple,ForCEO.
also suggest we want change itemRenderer by choosing in a combobox.
Here is code:
<mx:Script>
<![CDATA[
[Bindable]
public var itemRenderProvider:ArrayCollection =new ArrayCollection(
[
{label:'Complex',itemRendererClass:'your.components.Complex'},
{label:'Simple',itemRendererClass:'your.components.Simple'},
{label:'justForCEO',itemRendererClass:'your.components.ForCEO'}
]);
private function onChangeItemRender(event:ListEvent):void{
var newItem:Object=event.currentTarget.selectedItem;
var newItemClass:Class=getDefinitionByName(newItem.itemRendererClass) as Class;
theList.itemRenderer=new ClassFactory(newItemClass);
}
]]>
</mx:Script>
<mx:ComboBox id="itemRenderChooser" dataProvider="{itemRenderProvider}" change="onChangeItemRender(event)" ></mx:ComboBox>
<mx:List id="theList" dataProvider="{dataProvider}"
//without next string lists row will not change height when renderer changed
variableRowHeight="true"
/>
Important notices:
use full path to your itemRenderer class like it the example show: 'your.components.Complex'
and
do not forget set variableRowHeight="true" for a instance of List
and
your itemRenderers will not work until you added it to an application. I mean the application will knew about them.
I solve this problem just place my itemRenderers to special state in main application
I hope it help to somebody.