2 Replies Latest reply on Feb 19, 2010 5:52 AM by jeffreypritchard

    Simple Tree Question

    jeffreypritchard Level 1

      Hello,

       

      I have a tree control which currently stays expanded all the time by using the following code:

       

      on the updateComplete event of the tree (tree) I call this:

       

      private function expandAllNodes(e:Event)

      {

           if (tree != null){

               if   (tree.dataProvider.length > 0){

                     tree.expandChildrenOf(tree.dataProvider[0]);

                }

            }

      }

       

      it works exactly the way I want it to and it keeps the tree open all the time. So far so good.

       

      But I'd like to do this instead:

       

      When an item is added to the tree (the dataProvider actually), expand all nodes (like it does now). But I'd also like to be able to collapse nodes if the list gets really long (which it might).

       

      However whenever I collapse a node, the updateComplete fires and opens it back up. Is there another event I should use instead of the updateComplete that wouldn't cause the expand all to get called again ?

       

      Thanks in advance,

       

      Jeff

       

       

       

        • 1. Re: Simple Tree Question
          archemedia Level 4

          A simple solution could be to set a flag:

           

          private var enableExpand:Boolean = true;

           

          In your expand handler add:

           

          if (tree != null && enableExpand){

                   if   (tree.dataProvider.length > 0){

                         tree.expandChildrenOf(tree.dataProvider[0]);

                    }

                }

          enableExpand = true;

           

          then, in your addItemToTree function or wherever you want, you can set the enableExpand property to false.

          It will then prevent the expand handler to execute one time.

           

          Dany

          • 2. Re: Simple Tree Question
            jeffreypritchard Level 1

            Hi,

             

            Thanks for helping me out, your solution fits nicely and works the way I wanted it to. I basically took what you said and modified it slightly because I'm using a dataDescriptor. So instead of setting enableExpand to false in the 'addItemToTree', I set it to false on the ITEM_CLOSE event of the tree which gets called before UPDATE_COMPLETE fires.

             

            So in effect, I now have a tree that fully expands when an item is added to it, but otherwise gives the user the functionality they would expect from a tree control (collapsing, expanding, etc).

             

            Thanks again for your help,