2 Replies Latest reply on Jan 17, 2007 6:33 PM by ntsiii

    Tree Traversal


      I'm looking to migrate a Flex app from 1.5 to 2.0 and I'm having problems with traversing a tree.

      I used to use command getTreeNodeAt, eg. treLinks.getTreeNodeAt(1).getTreeNodeAt(2)

      Can't see how to do something similar in Flex 2? Does anyone have any suggestions or examples on how to do this?

        • 1. Re: Tree Traversal
          Yes, I had some fun doing that one myself. The move from 1.5 to 2.0 was hell. I only hope the next upgrade is much, much smoother.

          anyway, I digress... There is a caveat in my example, I used a xml file to be the data provider for the tree, so using an XMLCollection to select what I wanted, worked well. I'm not sure what your set up is. Anyway, the code:

          <mx:Tree xmlns:mx=" http://www.adobe.com/2006/mxml"
          dataDescriptor="{new DefaultDataDescriptor()}"

          <mx:XML id="authenticatedXML" source="pmportal_menu_authenticated.xml"/>
          import mx.controls.treeClasses.DefaultDataDescriptor;
          import mx.collections.XMLListCollection;

          public function creationComplete():void
          this.dataProvider = authenticatedXML;
          var xmlListCollection:XMLListCollection = XMLListCollection(this.dataProvider);
          this.expandItem(xmlListCollection.getItemAt(0), true);
          var xmlListCollection2:XMLListCollection = new XMLListCollection(xmlListCollection.children());
          this.expandItem(xmlListCollection2.getItemAt(1), true);

          var xmlListCollection3:XMLListCollection = new XMLListCollection(xmlListCollection2.source.child("FindCompany"));
          this.selectedItem = xmlListCollection3.getItemAt(0);


          Essentially, you have to transverse the xml to get the item. There is probably a better way to do this.....(as this is extremely clunky), hopefully someone can pipe up on how this should be done.

          • 2. Re: Tree Traversal
            ntsiii Level 3
            I advise using e4x XML as the dataProvider for the tree. It is by nature hierarchical and has very powerful search and navigation functionality.

            There are many examples on CFLEX.net. Search for "tree".