[Embed(source="Image/Point.jpg")]
public var mPoint:Class;
[Embed(source="Image/Line.jpg")]
public var Line:Class;
[Embed(source="Image/Region.jpg")]
public var Region:Class;
[Embed(source="Image/Text.jpg")]
public var Texts:Class;
private var mDsName:String="SDE";
[Bindable]
private var company:XML =
<list>
<department title={mDsName} code="200">
</department>
</list>;
[Bindable]
private var companyData:XMLListCollection = new XMLListCollection(company.department);
/*
加载Tree
*/
private function AddDtSet(mDataSource:se_mobile_datasource ):Boolean
{
if (mDataSource==null)
{
return false;
}
if( mDataSource.m_vDatasets==null)
{
return false;
}
var mDtV:Vector.<se_mobile_dataset>=mDataSource.m_vDatasets;
for(var i:int=0;i<mDtV.length;i++)
{
var mDtName:String=mDtV[i].m_sDtName;//数据集集合
var mType:int=mDtV[i].m_nDttype;//类型
addEmployee(mDtName,mType);
}
return true;
}
private function treeLabel(item:Object):String
{
var node:XML = XML(item);
if( node.localName() == "department" )
return node.@title;
else
return node.@name;
}
private function addEmployee(tt:String,type:int):void
{
var newNode:XML = <employee/>;
newNode.@name =tt;
var dept:XMLList =company.department.(@title == "SDE");
if( dept.length() > 0 ) {
dept[0].appendChild(newNode);
tree.setItemIcon(tree.dataProvider.getItemAt(0), rootOpenIcon, rootOpenIcon);
//更换子节点图标
switch(type)
{
case 1://点
tree.setItemIcon(tree.dataDescriptor.getData(newNode),mPoint,mPoint);
break;
case 2://线
tree.setItemIcon(tree.dataDescriptor.getData(newNode),Line,Line);
break;
case 3://面
tree.setItemIcon(tree.dataDescriptor.getData(newNode),Region,Region);
break;
case 4://文本
tree.setItemIcon(tree.dataDescriptor.getData(newNode),Texts,Texts);
break;
}
}
}
/*
获取选中节点名称
*/
protected function tree_changeHandler(event:ListEvent):void
{
Alert.show(tree.selectedItem.@name);
}
<mx:Tree id="tree" left="{SetScreenSize(2)+230}" x="0" y="20" width="188" height="339" backgroundColor="white"
borderColor="black" change="tree_changeHandler(event)" dataProvider="{companyData}"
iconField="@icon" labelFunction="treeLabel">
</mx:Tree>