Set Icons for Items in a List
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Canvas width="400" height="300">
<mx:Script>
[Bindable]
private var dp:Array = [{name:"A", position:"a"},
{name:"B", position:"b"},
{name:"C", position:"c"},
{name:"D", position:"d"}];
[Embed(source="a.png")]
private var managerIcon:Class;
[Embed(source="a.png")]
private var designerIcon:Class;
[Embed(source="a.png")]
private var accountantIcon:Class;
[Embed(source="a.png")]
private var developerIcon:Class;
private function setIcon(value:*):Class
{
if(value.position != null)
{
switch(value.position)
{
case "developer":
return developerIcon;
break;
case "designer":
return designerIcon;
break;
case "accountant":
return accountantIcon;
break;
case "manager":
return managerIcon;
break;
}
}
return null;
}
</mx:Script>
<mx:List width="200"
id="listImpl"
labelField="name"
dataProvider="{dp}"
editable="true"
iconFunction="setIcon"/>
</mx:Canvas>
</mx:Application>
Related examples in the same category