3 Replies Latest reply on Oct 31, 2010 10:22 PM by SrinivasanJR

    Adding Node and Deleting Node in Tree

    SrinivasanJR Level 1


      I am building a tree dynamically.


      I have a class which has set of properties.I am constructing as follows.


      public class TreeNode
              public function TreeNode()
           public var friendlyName:String;
           public var icon:Class;
           public var children : Array;
           public var logicalName:String;
           public var neType:String;
           public var arrayColl:ArrayCollection = new ArrayCollection();
           public function addChild(node:TopoTreeNode):void
               if (this.children == null){
                   this.children = new Array();
               arrayColl.source = children;    
           public function clearChild():void
               children = null;
           public function removeChild(arrayIndex:int):void
               if(children != null)
               arrayColl.source = children;


      Then I set the dataProvider as follows where treeModel is object that is injected.



      <mx:Tree id="tree"
                   showScrollTips="true" showDataTips="true" dataTipFunction="{treeModel.getDisplayName}" allowMultipleSelection="true" click="treeModel.displayItemInWorkingView(tree.selectedItems);"/>



      TreeModel has the following variables


              public var rootNode:TopoTreeNode = new TopoTreeNode(); // this is the rootNode.
              public var rootChild:TopoTreeNode = new TopoTreeNode(); // this is the child of the root node..

      While constructing the tree, it is working fine.


      But after this when i try to add a node (ie adding a node as child to rootNode), it is getting added to my rootNode object but it is not getting displayed


      When i click on the items in the tree or click on the drop menu in the tree it is getting displayed.


      But i want it to be shown in the tree without clicking anything.


      Could anyone help on this?