Skip to main content
Participant
November 4, 2009
Question

Cannot add items to HierarchicalCollectionView when parent is a leaf

  • November 4, 2009
  • 1 reply
  • 1129 views

Hi,

I cannot use the addChild function on a hierarchicalCollectionView object, when the parent element is a leaf node.

When the selected node already has children, it works, but if the new node would be the first child, addChild returns false.

How can I add a new child to a leaf?

Attached you'll find a small example (rename .txt to .mxml then). Try to click on the button when "Part1_1" is selected in the tree. -> doesn't work. If any other nodes are selected, it works.

Thanks a lot for you help,

Bye,

Fritz

This topic has been closed for replies.

1 reply

Participant
November 17, 2009

Hi,

i found the solution myself. You've to extend the HierarchicalData class and override the canHaveChildren function to automatically allow every node to have children.


package {
    import mx.collections.HierarchicalData;


    public class EditableHierarchicalData extends HierarchicalData {
        public function EditableHierarchicalData(value:Object = null) {
            super(value);
        }


        /**
         * Override this method to allow any node to have a children.
         */
        override public function canHaveChildren(node:Object):Boolean {
            return true
        }
    }
}

Bye,

Fritz

PS. I found this solution in an example of ILOG Elixir's OrgChart.

Known Participant
December 30, 2009

Hi Fritz,

Thanks for this, you've helped me streamline my add and delete node code.  I have a questions on how to get the folder to change to an item (leaf) when you'ved delete the last one. The only way I can get it change icons is by setting the children to null, but this creates problems down the line.  I'm going to start a new thread and post my source.  Thx.