1 Reply Latest reply on Aug 23, 2010 9:33 PM by Flex harUI

    How to override child node controls in a Flex Tree control

    Devtron Level 3

      Hello,

       

      I am currently developing a dynamic LineChart in FLEX 4. I am implementing a Tree control next to my LineChart, which will filter the LineChart dataprovider and lineseries. The tree control has several branches and ultimately 5 children (leaf nodes) at the bottom of the last branch.

       

      I need the leaf node/children to be displayed as checkboxes inside the tree control. As I understand, this will require overrides in the TreeItemRenderer class. This is where I am a little confused on how to implement that.

       

      Currently I can distinguish between leaf and branches using this code, in my main MXML component. I added this because it may be helpful to some beginning FLEX developers, such as myself, who cannot easily find this functionality documented well:

       

                      private function treeClick(e:ListEvent):void {
                     
                      _selectedItem = Tree(e.currentTarget).selectedItem;
                     
                      if(mainTree.dataDescriptor.isBranch(_selectedItem)) {
                          Alert.show('branch click');
                      }
                      else {
                          Alert.show('leaf node click');
                      }
                         
                  }

       

      I am looking at the TreeItemRenderer override class from the following example here: http://www.sephiroth.it/file_detail.php?id=151

       

      In the example, they override the "createChildden" super function to add checkboxes to the tree control.

       

      My question is, **can I override the createChildren function directly in my MXML component, and not have to use an entire class file to override this functionality? Must I re-invent the wheel to do this?**

       

      **Also, how can I distinguish that my treeItem is a leaf node and not a parent, in the override function?** I only want to add checkboxes to the leaf nodes, how can I differentiate? The following example adds checkboxes to all branches and leaf nodes, but I want to add checkboxes only to leaf node/children. How would you approach that?

       

                  override protected function createChildren( ): void
                  {
                      super.createChildren( );
                      if( !_checkbox )
                      {
                          _checkbox = new CheckBoxExtended( );
                          _checkbox.allow3StateForUser = false;
                          _checkbox.addEventListener( MouseEvent.CLICK, onCheckboxClick );
                          addChild( _checkbox );
                      }
                  }