Search Tree Node Variables
MXML File
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="createAccor();" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#6A6A6A, #6A6A6A]">
<mx:XMLList id="data">
<node>
<node name="A">
<node name="A1" surname="a1" age="21" wage="1200"/>
<node name="A2" surname="a2" age="22" wage="1000">
<node name="A2.2" surname="a2" age="22" wage="1000"/>
<node name="A2.3" surname="a2" age="22" wage="1000">
<node name="A2.7" surname="a2" age="22" wage="1000"/>
<node name="A2.8" surname="a2" age="22" wage="1000"/>
<node name="A2.9" surname="a2" age="22" wage="1000"/>
<node name="A2.10" surname="a2" age="22" wage="1000"/>
</node>
<node name="A2.4" surname="a2" age="22" wage="1000"/>
<node name="A2.5" surname="a2" age="22" wage="1000"/>
</node>
<node name="A3" surname="a3" age="23" wage="1200"/>
<node name="A4" surname="a4" age="24" wage="1500"/>
</node>
<node name="B">
<node name="B1" surname="b1" age="21" wage="1900"/>
<node name="B2" surname="b2" age="22" wage="1500"/>
<node name="B3" surname="b3" age="23" wage="1200"/>
</node>
<node name="C">
<node name="C1" surname="c1" age="29" wage="1500"/>
<node name="C2" surname="c2" age="45" wage="1500"/>
</node>
</node>
</mx:XMLList>
<mx:Script>
<![CDATA[
import mx.core.Container;
import mx.controls.Tree;
import mx.containers.Canvas;
import mx.collections.XMLListCollection;
[Bindable]
private var searchResult:XMLList;
private var searchResultIndex:uint = 0;
public function createAccor():void
{
trace(data.node.length());
for(var i:int=0; i<data.node.length(); i++)
{
var AcorCan:Canvas=new Canvas();
AcorCan.percentWidth=100;
AcorCan.percentHeight=100;
AcorCan.label=data.node[i].@name;
trace("node"+data.node[i].@name);
pannelAcord.setStyle("fontColor","#000000");
var acorsectiontree:Tree=new Tree();
acorsectiontree.percentWidth=100;
acorsectiontree.percentHeight=100;
acorsectiontree.showRoot=true;
acorsectiontree.setStyle("defaultLeafIcon",null);
acorsectiontree.setStyle('useRollOver',true);
var dummyxml:XMLList=new XMLList(data.node[i].node);
trace("dym"+dummyxml);
acorsectiontree.dataProvider=dummyxml;
acorsectiontree.labelField="@name";
acorsectiontree.percentWidth=100;
AcorCan.addChild(acorsectiontree);
pannelAcord.addChild(AcorCan);
}
}
public var val:int;
private function findByName():void
{
var searchStr:String =searchtext.text;
for(var i:int=0; i<data.node.length(); i++)
{
for(var j:int=0; j<data.node[i]..@name.length(); j++)
{
if(data.node[i]..@name[j]==searchStr)
{
pannelAcord.selectedIndex=i;
val=new int(i);
}else{trace("False");}
}
}
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandChildrenOf(data[0], false);
searchResult = data.node..node.(@name.toLowerCase().search(searchStr.toLowerCase()) > -1);
trace("SEARCH"+searchResult);
searchResultIndex = 0;
if (searchResult[searchResultIndex] != undefined)
expandNode(searchResult[searchResultIndex]);
trace("SR"+searchResult);
}
private function expandNode(xmlNode:XML):void
{
while (xmlNode.parent() != null) {
xmlNode = xmlNode.parent();
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandItem(xmlNode, true, false);
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).selectedItem = searchResult[searchResultIndex];
trace("Enter"+xmlNode);
}
}
]]>
</mx:Script>
<mx:TextInput x="121" y="77" id="searchtext"/>
<mx:Button x="289" y="77" label="Search" click="findByName()"/>
<mx:Canvas x="121" y="122" width="233" height="337">
<mx:Accordion id="pannelAcord" width="100%" height="100%">
</mx:Accordion>
</mx:Canvas>
</mx:Application>
Search Tree Node Variable Demo
MXML File
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="createAccor();" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#6A6A6A, #6A6A6A]">
<mx:XMLList id="data">
<node>
<node name="A">
<node name="A1" surname="a1" age="21" wage="1200"/>
<node name="A2" surname="a2" age="22" wage="1000">
<node name="A2.2" surname="a2" age="22" wage="1000"/>
<node name="A2.3" surname="a2" age="22" wage="1000">
<node name="A2.7" surname="a2" age="22" wage="1000"/>
<node name="A2.8" surname="a2" age="22" wage="1000"/>
<node name="A2.9" surname="a2" age="22" wage="1000"/>
<node name="A2.10" surname="a2" age="22" wage="1000"/>
</node>
<node name="A2.4" surname="a2" age="22" wage="1000"/>
<node name="A2.5" surname="a2" age="22" wage="1000"/>
</node>
<node name="A3" surname="a3" age="23" wage="1200"/>
<node name="A4" surname="a4" age="24" wage="1500"/>
</node>
<node name="B">
<node name="B1" surname="b1" age="21" wage="1900"/>
<node name="B2" surname="b2" age="22" wage="1500"/>
<node name="B3" surname="b3" age="23" wage="1200"/>
</node>
<node name="C">
<node name="C1" surname="c1" age="29" wage="1500"/>
<node name="C2" surname="c2" age="45" wage="1500"/>
</node>
</node>
</mx:XMLList>
<mx:Script>
<![CDATA[
import mx.core.Container;
import mx.controls.Tree;
import mx.containers.Canvas;
import mx.collections.XMLListCollection;
[Bindable]
private var searchResult:XMLList;
private var searchResultIndex:uint = 0;
public function createAccor():void
{
trace(data.node.length());
for(var i:int=0; i<data.node.length(); i++)
{
var AcorCan:Canvas=new Canvas();
AcorCan.percentWidth=100;
AcorCan.percentHeight=100;
AcorCan.label=data.node[i].@name;
trace("node"+data.node[i].@name);
pannelAcord.setStyle("fontColor","#000000");
var acorsectiontree:Tree=new Tree();
acorsectiontree.percentWidth=100;
acorsectiontree.percentHeight=100;
acorsectiontree.showRoot=true;
acorsectiontree.setStyle("defaultLeafIcon",null);
acorsectiontree.setStyle('useRollOver',true);
var dummyxml:XMLList=new XMLList(data.node[i].node);
trace("dym"+dummyxml);
acorsectiontree.dataProvider=dummyxml;
acorsectiontree.labelField="@name";
acorsectiontree.percentWidth=100;
AcorCan.addChild(acorsectiontree);
pannelAcord.addChild(AcorCan);
}
}
public var val:int;
private function findByName():void
{
var searchStr:String =searchtext.text;
for(var i:int=0; i<data.node.length(); i++)
{
for(var j:int=0; j<data.node[i]..@name.length(); j++)
{
if(data.node[i]..@name[j]==searchStr)
{
pannelAcord.selectedIndex=i;
val=new int(i);
}else{trace("False");}
}
}
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandChildrenOf(data[0], false);
searchResult = data.node..node.(@name.toLowerCase().search(searchStr.toLowerCase()) > -1);
trace("SEARCH"+searchResult);
searchResultIndex = 0;
if (searchResult[searchResultIndex] != undefined)
expandNode(searchResult[searchResultIndex]);
trace("SR"+searchResult);
}
private function expandNode(xmlNode:XML):void
{
while (xmlNode.parent() != null) {
xmlNode = xmlNode.parent();
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandItem(xmlNode, true, false);
((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).selectedItem = searchResult[searchResultIndex];
trace("Enter"+xmlNode);
}
}
]]>
</mx:Script>
<mx:TextInput x="121" y="77" id="searchtext"/>
<mx:Button x="289" y="77" label="Search" click="findByName()"/>
<mx:Canvas x="121" y="122" width="233" height="337">
<mx:Accordion id="pannelAcord" width="100%" height="100%">
</mx:Accordion>
</mx:Canvas>
</mx:Application>
Search Tree Node Variable Demo