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


Brendan

--- In flexcoders@yahoogroups.com, "Pat Buchanan" <[EMAIL PROTECTED]> wrote:
>
> Brendan - thank you so much for the additional information.  I'm sure it
> will prove helpful. Do you know if this FAST architecture is
compatible with
> Flex 2?
>
> However, if anyone out there happens to run into a self contained, fully
> running simple example (with source) please pass along the URL.  If
I can
> finally get one running, I will post the source here.
>
> It would be greatly appreciated.
>
> Oh - and Flex 2 is the target, of course.  :)
>
> Thank you!
> -Pat Buchanan
>
>
>
> On 2/24/06, Brendan Meutzner <[EMAIL PROTECTED]> wrote:
> >
> > Pat,
> >
> > Have a look at the object inspector tool in the FAST toolkit...
> >
> > http://www.macromedia.com/devnet/flex/articles/fast_userguide.html
> >
> > Pay attention to:
> >
> > EchoConsole.mxml
> > EchoConsoleconnection.as
> > EchoAppConnection.as
> >
> > You'll have to figure out your remote calls, but this does show the
> > dynamic construction of a tree dataProvider.... might help...
> >
> >
> > Brendan
> >
> >
> >
> > --- In flexcoders@yahoogroups.com, "Pat Buchanan" <ajillis@> wrote:
> > >
> > > Hello fellow Flex coders!  Greetings from the frozen state of Utah.
> > >
> > > Well, I'm stuck.  I see a lot of people asking for examples of how
> > to do a
> > > dynamic tree.  Dynamic as in JUST loading the first level of nodes,
> > and when
> > > the user opens a node, it calls back to the server, gets it's
> > children, and
> > > adds them to the tree dynamically.
> > >
> > > (The reason I can't load the tree all at once is because it can be
> > > recursive, so the tree would go forever.)
> > >
> > > Anyway, I have searched the list archive and I see a LOT of
answers with
> > > either a quick explanation or tiny partial code snippet, but
have yet to
> > > find a COMPLETE running example.  Every time I find what I'm looking
> > for via
> > > Google, it links back to a certain pay site and I can't justify $250
> > for a
> > > few lines of example code.
> > >
> > > Does anyone know of a fully working dynamic tree example with
source?
> > >
> > > I'm POSITIVE it's right under my nose and I'll feel like a twinkie
> > when it's
> > > pointed out to me.  :(
> > >
> > > Thanks ya'all
> > > -Pat Buchanan
> > >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>






--
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