|
I think , the Flex 2.0 Tree related classes have been changed quite a
bit with the introduction of Hierarchical Data Providers and stuff. Here is some 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> ********************************************************************* Jason Y. Kwong wrote: I'm really at a lost as to how we're supposed to work with the hierarchical data that's used with the Tree component. The XML approach seems to be the most supported at the moment, so consider this simple XML: -- 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: Tree control in Flex 2 Beta 1 Hari Kolasani
- Re: [flexcoders] Re: Tree control in Flex 2 Beta 1 Jason Y. Kwong
- Re: [flexcoders] Re: Tree control in Flex 2 Beta 1 Jason Y. Kwong

