0 Replies Latest reply on Aug 17, 2010 2:04 PM by fresher4flex

    Add a button to the branch/root in a Flex Tree

    fresher4flex Level 1

      Can someone provide me code or  guide me how to  add a button to all nodes that has children/leaf( but not  to leaf). I tried from the example in this link

      http://www.remwebdevelopment.com/dev/a31/Flex-Checkbox-TreeItemRenderer.html , but I ma getting buttons for all the nodes(including leaf).

      i need to hav ethe button on the rideside corners horizontally to all branches/root.

       

      Please correct me where i am wrong or provide me correct code. Thanks in advance

       

       

       

      package

       

       

       

       

       

      PKG

      {

       

      import mx.controls.Button;

       

      import mx.controls.Tree;

       

      import mx.controls.treeClasses.TreeItemRenderer;

       

      import mx.controls.treeClasses.TreeListData;

       

      public class TreeData extends TreeItemRenderer

      {

       

      private var bWidth:Number = 30;

       

      private var bHeight:Number = 20;

       

      public function TreeData()

      {

       

      super();

      }

       

      var btn:Button=new Button();

       

      override protected function createChildren():void

      {

       

      //addChild(btn);

       

       

      super.createChildren();

      }

       

      override public function set data(value:Object):void

      {

       

      super.data = value;

       

      // get the tree that owns us

       

      var _tree:Tree = Tree(this.parent.parent);

       

      // if the current node is a branch node

       

      //for each(item:Object in

       

      if(TreeListData(super.listData).depth=1)                             -or if(TreeListData(super.listData).hasChildren)   these are not working for me

      {

      btn.width = bWidth;

      btn.height= bHeight;

      btn.label=

      "Remove Attachment";

      btn.right=10;

       

       

      }

       

      else

      {

      /////////

       

      }

      }

       

       

       

       

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{

       

      super.updateDisplayList(unscaledWidth,unscaledHeight);

       

      if(super.data){

       

      var tld:TreeListData = TreeListData(super.listData);

       

      // if the current node is a branch node

       

      if(TreeListData(super.listData).depth=1)

      {

       

      this.btn.visible=true;

       

      this.btn.x=200;

       

      this.btn.y = super.label.y+4;

       

      //super.label.x = this.btn.x +;

       

      //this.btn.y = super.label.y+8;

       

      }

       

      else

      {

       

      this.btn.visible=false;

       

      this.btn.includeInLayout=false;

      }

      }

       

      }

       

       

       

       

      }

      }