This content has been marked as final. Show 2 replies
Yes, we see the need for this functionality and there is a bug logged for this specific use case.
It's deferred for now, however. I"ll post more info if I can find some.
If you take a look at the Tree property, dataDescriptor, you'll see that its a property that implements the ITreeDataDescriptor interface. This interface describes the contract that the Tree uses to parse the data bound to it. You'll notice there is a method called isBranch() which, given a node of data, returns whether that node should be treated as a branch node or a leaf node.
In your example, when the last node is removed from a branch node via a successful drag and drop action, we want that node to still be treated as a branch. All you have to do is extend Tree and modify the dragCompleteHandler() event to do this. I'm copying and pasting my code below. You'll see that before I call super.dragCompleteHandler() I check to see if the parent of the item being dragged is dragging its last child, in which case we force that parent node to stay a branch by setting the isBranch attribute to true. I'm assuming the data is XML but if your data is in Array form, you can still do something similar.
// ActionScript file
public class myTree extends Tree
public function myTree()
override protected function dragCompleteHandler(event:DragEvent):void
var items:Array = event.dragSource.dataForFormat("treeItems") as Array;
for (var i:int = 0; i < items.length; i++)
parent = getParentItem(items );
childCollection = dataDescriptor.getChildren(parent);
if (childCollection.length == 1)
//we are removing the last child of this parent folder,
//we want to make sure it appears as a branch
parent.@isBranch = true;