views:

1478

answers:

3

hi guys, 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)"         
         />
A: 

temporarily solved the problem by listening to dragComplete on the tree
dragComplete="handleDragComplete(event)

When the drag is complete i get the changed dataprovider from the tree and then i recursively search the "dragged item"("id" + "label") in the changed dataprovider to find its position in the tree ie. "id" of the node in which the selected node is dropped(parent node). and fire the save to database api.

anyone has better options. pls reply

thanks :)

Amitd
see this linkhttp://www.adobe.com/devnet/flex/quickstart/working_with_tree/
Amitd
+1  A: 

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

LE GALL Benoît
A: 

LE GALL Benoît, merci! Your function is exactly what I needed!

Eugene