All, I have a Datagrid with an ItemRenderer assigned to a column which is a Currency column(String). The renderer is mean to display the Flag of the currency eg; for USD it should display a USD flag image etc. At the moment the column is appearing Blank without an image. I have the following renderer (which extends UIComponent). I am dynamically loading the images in the commitProperties() method. At the moment I have hard-coded it to the USD image to get it to work - but no luck. Any help would be greatly appreaciated.
public class CenteredEmbedImage extends UIComponent implements IListItemRenderer,IDropInListItemRenderer
{
private var _loader:Loader;
private var _img:Image;
public function CenteredEmbedImage()
{
super();
}
private var _data:Object;
[Bindable("dataChange")]
[Inspectable(environment="none")]
public function get data():Object
{
return _data;
}
public function set data(value:Object):void
{
var newText:*;
_data = value;
invalidateProperties();
dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
}
private var _listData:BaseListData;
[Bindable("dataChange")]
[Inspectable(environment="none")]
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = value;
}
override protected function commitProperties():void
{
super.commitProperties();
if (listData)
{
// remove the old child if we have one
if (_img)
removeChild(_img);
_img= new Image();
//source code of the second way
_loader = new Loader();
//notice: NOT _loader.addEventListener,is _loader.contentLoaderInfo.addEventListener
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{_img.source = e.currentTarget.content;});
_loader.load(new URLRequest(encodeURI("assets/images/flags/usd.gif")));
addChild(_img);
}
}
override protected function measure():void
{
super.measure();
if (_img)
{
measuredHeight = _img.height;
measuredWidth = _img.width;
}
}
override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
if (_img)
{
_img.x = (w - _img.width) / 2;
}
}
}
}