Conditional Drag and Drop Operations in Flex/AS3 Tree

Posted by user163757 on Stack Overflow See other posts from Stack Overflow or by user163757
Published on 2010-03-25T13:44:26Z Indexed on 2010/05/16 22:30 UTC
Read the original article Hit count: 491

Filed under:
|
|

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:

  1. Only parent/top level nodes can be moved
  2. 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?

© Stack Overflow or respective owner

Related posts about flex

Related posts about tree