Conditional Drag and Drop Operations in Flex/AS3 Tree
- by user163757
Good day everyone.
I am currently working with a hierarchical tree structure in AS3/Flex, and want to enable drag and drop capabilities under certain conditions:
Only parent/top level nodes can be moved
Parent/top level nodes must remain at this level; they can not be moved to child nodes of other parent nodes
Using the dragEnter event of the tree, I am able to handle condition 1 easily.
private function onDragEnter(event:DragEvent):void
{
// only parent nodes (map layers) are moveable
event.preventDefault();
if(toc.selectedItem.hasOwnProperty("layer"))
DragManager.acceptDragDrop(event.target as UIComponent);
else
DragManager.showFeedback(DragManager.NONE);
}
Handling the second condition is proving to be a bit more difficult. I am pretty sure the dragOver event is the place for logic. I have been experimenting with calculateDropIndex, but that always gives me the index of the parent node, which doesn't help check if the potential drop location is acceptable or not. Below is some pseudo code of what I am looking to accomplish.
private function onDragOver(e:DragEvent):void
{
// if potential drop location has parents
// dont allow drop
// else
// allow drop
}
Can anyone provide advice how to implement this?