tree.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" width="226" height="673">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
private function tree_itemClick(evt:ListEvent):void {
var t:Tree = evt.currentTarget as Tree;
var dataObj:Object = evt.itemRenderer.data;
if (dataObj.hasOwnProperty("@src")) {
//test.text=dataObj.@src;
navigateToURL(new URLRequest(dataObj.@src),"mainFrame"); //mainFrame为右框架名称
}
else if (t.dataDescriptor.isBranch(t.selectedItem)) {
// test.text="";
}
}
private function tree_labelFunc(item:Object):String {
var suffix:String = "";
if (tree.dataDescriptor.isBranch(item)) {
suffix = " (" + item.children().length() + ")";
}
return item.@label + suffix;
}
]]>
</mx:Script>
<mx:XML id="dp" source="dp2.xml" />
<mx:Tree id="tree"
dataProvider="{dp}"
labelFunction="tree_labelFunc"
showRoot="false"
width="100%"
height="100%"
itemClick="tree_itemClick(event);" />
</mx:Application>