【发布时间】:2010-12-22 13:58:00
【问题描述】:
所有,我有一个 Datagrid,其中 ItemRenderer 分配给一个列,该列是一个货币列(字符串)。渲染器的意思是显示货币的标志,例如;对于美元,它应该显示美元标志图像等。目前该列显示为空白,没有图像。我有以下渲染器(它扩展了 UIComponent)。我在 commitProperties() 方法中动态加载图像。目前,我已将其硬编码为 USD 图像以使其正常工作 - 但没有运气。任何帮助将不胜感激。
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;
}
}
}
}
【问题讨论】:
标签: apache-flex image datagrid itemrenderer