如何动态更改tree的节点的图标

2025-05-11 12:07:56
推荐回答(1个)
回答(1):

  修改tree节点的图标的步骤如下:
  首先,在src下建立一个assets文件夹,放几张图片;
  其次,编写代码如下:
  


[Embed(source="assets/boy.jpg")]
public var boyIcon:Class;

[Embed(source="assets/girl.jpg")]
  public var girlIcon:Class;

// 根据结点的属性设置节点图标
private function SetIcon(item:Object):*
{
var xml:XML = item as XML;

if(xml.attribute("sex")=="boy")
{
return boyIcon;
}
else
{
return girlIcon; }
}

// Tree控件的数据源
[Bindable]
public var departmentTree:XML=










]]>

   height="450" id="treeXml"
dataProvider="{departmentTree}" labelField="@name"
showDataTips="true" iconFunction="SetIcon" />

  最后,运行效果即可。