Here is an example posted on the MM forum some time ago:

 

Tariq, if you are listening, maybe this should go in your examples.

 

Tracy

 

There is an unexpected behavior with the dropLocation: Sometimes it does not return the correct integer. For example, expand all the nodes and try to drag node "Four" into the "first(0)" position in branch "one". GetDropLocation() returns a "1" not a "0" as I would expect. If anyone has any insights I would like to hear, as I am fighting with this situation in my own application.

Attach Code

<?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
      <mx:Script>
        <![CDATA[
        import mx.managers.DragManager;
 
        function doDragEnter(event) {
               event.handled = true;
        }
               
        function doDragExit(event) {
               event.target.hideDropFeedback();
        }
               
        function doDragOver(event) {
               event.target.showDropFeedback();
        }
               
        function doDragDrop(event) {
               doDragExit(event);
               var dragNodes = event.dragSource.dataForFormat("source").selectedItems;
               var toNode = event.target.getDropParent();
               var idex = event.target.getDropLocation();
               event.target.clearSelected();
               var imax = dragNodes.length;
               
               for( var i=0; i < imax; i++ ) {
                       taStatus.text = taStatus.text + "\n" + "Adding node at index: " + idex;
                       toNode.addTreeNodeAt( idex, dragNodes[i] );
               }
        
        }
        
        function doDragComplete(event) {
               var dragNodes = event.dragSource.dataForFormat("source").selectedItems;
               var imax = dragNodes.length;
               
               for( var i=0; i < imax; i++ ) {
                       var node = dragNodes;
                       node.removeTreeNode();
               }
        }
      ]]></mx:Script>
               
      <mx:Tree id="navigator" editable="true" heightFlex="1" dragEnabled="true" 
                  dragEnter="doDragEnter(event)" dragExit="doDragExit(event)" dragOver="doDragOver(event)" 
                  dragDrop="doDragDrop(event)" dragComplete="doDragComplete(event)" >
         <mx:dataProvider>
            <mx:XML>
               <node label="A">
                  <node label="One">
                     <node label="abc"/>
                     <node label="def"/>
                  </node>
                  <node label="Two" />
               </node>
               <node label="B">
                  <node label="Three" />
                  <node label="Four" />
               </node>
            </mx:XML>
         </mx:dataProvider>
      </mx:Tree>
      <mx:TextArea id="taStatus" width="300" height="100" />
  </mx:Application>

 

 

 


From: Pilby [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 11:34 AM
To: Flex Coders
Subject: [flexcoders] RE: Tree component confusion

 

My objective is to allow the user to drag a tree node and drop it on another node, and then reflect visually the changes he/she has made.

 

I since learned this is a lot more complicated than meets the eye because the index of the drop location seems to change. From what I have seen, the moment a branch opens, its index becomes 0, and when it's closed, it's index becomes relative to its parent node. So if Node A is the topmost node, and Node B is its child node, while Node B is closed, it's index is 1, but the moment I open Node B, it's index becomes 0.

 

This is a problem because the only method I see that I can use for my purpose is the addTreeNodeAt(index). And if there were multiple branches open in the entire tree, we end up having multiple nodes with the SAME index!

 

Can anyone give me an example of a drag-n-drop operation entirely within a tree? The examples I have found deal with dragging datagrid items on a tree, or dragging items from a tree to a list box. What about an example that drags a tree item and drops on another tree item within the same tree?



Reply via email to