6/13/2010 9:47:31 PM
Title:
displaying icons in grid column programmatically
hi, I have dynamically created advanced datagrid..I want to display one icons in column if value is male, or if value is female i want to display another icon.. my code is,
column.itemRenderer=new averageComponent();
public class averageComponent extends Image implements IFactory
{
[Bindable]
[Embed(source='/assets/maleButton.png')]
public var male:Class;
[Bindable]
[Embed(source='assets/femaleButton.png')]
public var female:Class;
public function averageComponent()
{
super();
}
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
var img:Image = new Image();
var dField:String = DataGridListData(listData).dataField;
//Alert.show(dField);
if(data[dField] =="M")
{
img.source = new male();
addChild(img);
belowAverage();
}
else
{
img.source = new female();
addChild(img);
}
}
}
public function newInstance():*
{
return new averageComponent();
}
}
but im not able to display the icon in grid column.. i have tried with all possible image paths also..but it is not working.. can anyone suggest me where im doing mistake?
6/13/2010 11:45:21 PM
img.source = female; try this
6/14/2010 1:24:10 AM
The code should be simple enough. You can simply write a function inside the item renderer which returns the image path. Below is just an code idea , syntax may not be correct as I am writing in notepad only. i.e
function imagePath(val:String):String{
if(val=="M"){
return femaleImage;
}else
{
return femaleImage;
}
}
<mx:image source="{imagePath(data[dField] =="M")}"