Here is a sample .mxml/as code that worked for me. Hope this will
help. - Hari ********************************************************************* <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" backgroundColor="#FFFFFF" creationComplete="initList()"> <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; var origXML:XML; public function initList() { myTree.rootVisible = false; //TODO: Get this XML from a data service var origXMLString:String = "<MyRoot> " + "<node1 label=\"supernode1\" someProp=\"sdsdf \" isBranch=\"true\"/>" + "<node2 label=\"supernode2\" someProp=\"sdsdf \" isBranch=\"true\"/>" + "<node3 label=\"supernode3\" someProp=\"sdsdf \" isBranch=\"true\"/>" + "</MyRoot>"; origXML = new XML(origXMLString); myTree.dataProvider = origXML; } public function open(event:Object) { var selectedNode:Object =event.node; var myXMLList:XMLList = new XMLList(selectedNode); //TODO: Get this XML from a data service based on the selected node. var newXMLString:String = "<childnode1 label=\"childnode1\" someProp=\"sdsdf \" isBranch=\"true\" />" + "<childnode2 label=\"childnode2\" someProp=\"sdsdf \" isBranch=\"false\" />" + "<childnode3 label=\"childnode3\" someProp=\"sdsdf \" isBranch=\"true\" />" ; var myNewXMLList:XMLList = new XMLList(newXMLString); selectedNode.setChildren(myNewXMLList); myText1.text = selectedNode.toXMLString(); myText2.text = myTree.dataProvider.source[0]; myTree.dataProvider = origXML; } public function close(event:Object) { var selectedNode:Object = event.node; var myXMLList:XMLList = new XMLList(selectedNode); removeAllDecendants(myXMLList); myText1.text = selectedNode.toXMLString(); myText2.text = myTree.dataProvider.source[0]; myTree.dataProvider = origXML; } public function removeAllDecendants(xmlList:XMLList) { var myDescendantXMLList:XMLList = xmlList.descendants(); var myDecendentXMLListCollection:XMLListCollection = new XMLListCollection(myDescendantXMLList); myDecendentXMLListCollection.removeAll(); } ]]> </mx:Script> <!-- Simple example to demonstrate the Tree control --> <mx:XML id="myxml"> </mx:XML> <mx:HDividedBox width="100%" height="100%"> <!-- Tree listing of directories (only) --> <mx:Box> <mx:Tree id="myTree" width="600" height="600" labelField="@label" defaultLeafIcon="@Embed('images/folder.gif')" nodeOpen="open(event)" nodeClose="close(event)"/> </mx:Box> <mx:VBox> <!-- Text Areas to Display Node XMLs --> <mx:Box> <mx:TextArea width="600" height="300" id="myText1" /> </mx:Box> <mx:Box> <mx:TextArea width="600" height="300" id="myText2" /> </mx:Box> </mx:VBox> </mx:HDividedBox> </mx:Application> ********************************************************************* Brendan Meutzner wrote: It doesn't work for 2.0 -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS
|
- Re: [flexcoders] Re: Full dynamic tree example Hari Kolasani
- Re: [flexcoders] Re: Full dynamic tree example Pat Buchanan
- Re: [flexcoders] Re: Full dynamic tree example Jignesh Dodiya