Open nodes in the Tree control based on the values of query string parameters
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="initApp()">
<mx:Script>
import mx.collections.XMLListCollection;
[Bindable]
private var treeData:XML =
<root>
<node label="A">
<node label="B">
<node label="C"/>
<node label="D"/>
</node>
<node label="E" isBranch="true"/>
<node label="F" isBranch="true"/>
</node>
<node label="G">
<node label="J" isBranch="true"/>
<node label="Q" isBranch="true"/>
<node label="W" >
<node label="R"/>
<node label="Y"/>
</node>
</node>
</root>;
private var openSequence:Array = [1,2,3];
private function initApp():void {
var nodeList:XMLListCollection = myTree.dataProvider as XMLListCollection;
var node:XMLList = nodeList.source;
for(var i:int=0; i < openSequence.length; i++) {
var j:int = openSequence[i];
var n:XML = node[j];
if( n.children() != null ) {
myTree.expandItem(n,true,false);
node = n.children();
} else {
break;
}
}
if( n != null ) myTree.selectedItem = n;
}
</mx:Script>
<mx:Tree id="myTree" y="88" width="221" height="257"
horizontalCenter="0" dataProvider="{treeData.node}"
labelField="@label" />
</mx:Application>
Related examples in the same category