Search code examples
apache-flexactionscript-3drag-and-droptree

Flex tree control drag drop .item position


just facing a difficulty with tree control drag drop..
Suppose i have tree with drag-drop enabled. I want to which node(id) is droped inside which node.

1]if i drag "Cat1" node inside "Cat3",i want to identify ids of siblings of "cat1",and "cat3".

2]in general i want to know the ids of current element being moved along with
its new parent and new position and save these postions.

3] Also "cat4" when moved outside "cat3",i want know its position and its siblings id.

<mx:XML id="treeDP">
        <node label="Categories">
          <node label="Cat1" id="1" isBranch="true"/>            
          <node label="Cat2" id="2" isBranch="true"/>

           <node label="Cat3" id="3" isBranch="true">
             <node label="Cat4" id="4" isBranch="true"/>
         </node>          
        </node>
</mx:XML>

    <mx:Tree id="compBalanced" 
        width="420" height="439" 
        dataProvider="{treeDP}" 
        showRoot="false"
        labelField="@label"
        doubleClickEnabled="true"
        dragEnabled="true" 
        dropEnabled="true" 
        dragDrop="onDragDrop(event)"            
            />

Solution

  • I've meet a problem like this, when I had to check the node wich receive the children. To get the node parent, I'd used this :

    public function getObjectTarget() : Object {
       var dropData : Object = tree.mx_internal::_dropData as Object;
       if (dropData.parent != null) {
          return dropData.parent;
       } else {
              // if there is not parent (root of the tree), I take the root directly
          var renderer : IListItemRenderer = tree.indexToItemRenderer(0);
          return renderer.data;
       }
    

    hope this will help some one