I have a list that uses a itemRendererFunction to get custom item renderers. Is there a way to only reevaluate one item in the list and get different item renderer?
imagine code like this :
there are two item renderers ItemRendererOne.mxml and ItemRendererTwo.mxml
Data.as
package {
public class Data {
private var _data : Boolean = false;
[Bindable]
public function get data():Boolean {
return _data;
}
public function set data(value:Boolean) : void {
_data = value;
}
public function Data(value : Boolean) {
_data = value;
}
}
}
and main app is
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" >
<fx:Script>
<![CDATA[
import mx.collections.ArrayList;
private var dataProvider : ArrayList = new ArrayList([new Data(true), new Data(false)]);
public function getItemRenderer(data : Object) : IFactory {
if (data.data) {
return new ClassFactory(ItemRendererOne);
} else {
return new ClassFactory(ItemRendererTwo);
}
}
protected function button1_clickHandler(event : MouseEvent) : void {
var data : Data = dataProvider.getItemAt(0) as Data;
data.data = !data.data;
}
]]>
</fx:Script>
<s:VGroup>
<s:List dataProvider="{dataProvider}" itemRendererFunction="{getItemRenderer}" />
<s:Button click="button1_clickHandler(event)" />
</s:VGroup>
</s:WindowedApplication>
Basically when someone clicks on the button, I want getItemRenderer to be called again and the item in the list is updated with new item renderer.