开发者

Conditional Drag and Drop Operations in Flex/AS3 Tree

开发者 https://www.devze.com 2022-12-24 07:23 出处:网络
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:

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 pro开发者_StackOverflow社区ving 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?


Okay, not sure if this tidbit will help you, but when I did it with XML I would get the object of the drop target with:

var r:int = dropTarget.calculateDropIndex(evt);
var node:XML = treeCurTemplate.indexToItemRenderer(r).data as XML;

Then I would compare the localName of the target to the localName of the item I was dragging. The localName was what I used to control the tree branching, so this made sense. Maybe you can use this to find some sort of way to do it with your objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消