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>

*********************************************************************

Brendan Meutzner wrote:
Hi,

Can someone provide me with an example of addTreeNode for Flex 2?  I
have a XML structure that is loaded into my Tree as the dataProvider.
I would like to be able to click on a node within the tree, and then
add a sub node into that selected node.  When I get the selectedNode
from the tree, and attempt call addTreeNode on it, I get an error
"Call attempted on an object that is not a function"...

Unfortunately, not much documentation on these methods yet, so any
help offered would be very much appreciated.

Brendan






--
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
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to