Hello all,
I've created an mxml page that displays a tree control, however the data is only being displayed as branches. Even items that are leaves are being displayed as branches. What am i doing wrong? Please help!
thanks, tone
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
public function init():void {
var item:Object;
var array:Array = new Array();
var xml:XML =
<course>
<section>
<title>Introduction to Actionscript</title>
<section>
<title>Lesson 1: Variables</title>
<section>
<title>Topic 1: Data types</title>
</section>
</section>
</section>
</course>;
item = parseStructure(xml);
array.push(item);
var arrColl:ArrayCollection = new ArrayCollection(array);
Tree.dataProvider = arrColl;
}
private function parseStructure(xml:XML):Object{
var obj:Object = new Object();
obj.label = xml.title;
if(xml.section != null) {
obj.children = new ArrayCollection();
for each (var child:XML in xml.section) {
obj.children.addItem(parseStructure(child));
}
}
return obj;
}
]]>
</mx:Script>
<mx:HBox>
<mx:Tree id="Tree" width="300"/>
</mx:HBox>