首先,在src下建立一个assets文件夹,放几张图片;
其次,编写代码如下:
[Embed(source="assets/boy.jpg")]
publicvarboyIcon:Class;
[Embed(source="assets/girl.jpg")]
publicvargirlIcon:Class;
//根据结点的属性设置节点图标
privatefunctionSetIcon(item:Object):*
{
varxml:XML=itemasXML;
if(xml.attribute("sex")=="boy")
{
returnboyIcon;
}
else
{
returngirlIcon;}
}
//Tree控件的数据源
[Bindable]
publicvardepartmentTree:XML=
]]>
dataProvider="{departmentTree}"labelField="@name"
showDataTips="true"iconFunction="SetIcon"/>
最后,运行效果即可。