4 Replies Latest reply on Jun 2, 2009 2:21 AM by sdoy

    Tree Drag & Drop problem identifying drop location

    fancycarp Level 1

      ----- Item1
      ---------- Item11
      ---------- Item12
      ----- Item2
      ---------- Item21
      ---------- Item22
      ----- Item3
      ---------- Item31
      ---------- Item32

      When I drag Item32 to drop at the location pointed by the arrow, it can be dropped as :
      1). A third child of Item1 or
      2). A Second child of Item0

      After drop, I need to update the database for Item32's new parent change.
      How can we identify new parent whether it is dropped as Case 1). or Case 2).

      Because the calculateDropIndex return the same index(of Item2) and cannot identify...

      Any suggestion?


        • 1. Re: Tree Drag &amp; Drop problem identifying drop location
          ntsiii Level 3
          I am sorry, but last time I tried to do drag and drop withing a tree i hit the same problem and failed to solve it. I actually gave up. The Tree as a target for drop operations leaves much to be desired. The feedback is poor, and I have yet to be able to add a child node to an empty node.

          If you solve this, please post and let us know how.

          • 2. Re: Tree Drag &amp; Drop problem identifying drop location
            Hi fancycarp
            i hope i may solve your problem
            include the following line on the dragdrop function which will be called when u drag and drop into the target

            var dropTarget:Tree = Tree(event.currentTarget);
            var r:int = dropTarget.calculateDropIndex(event);

            // r will give you the index where you r dropping

            var node:XML = productTree1.selectedItem as XML; //productTree1=id of the tree
            // while node.parent().@name will give you, to which parent you have added.

            hope this will solve your problem..:-)
            • 3. Re: Tree Drag &amp; Drop problem identifying drop location
              That -almost- works. Unfortunately, when you try to drag and drop to the end of the Tree (as in past Item32) the parent will always come back as Item3, even if the actual drop point is at the root node.

              This definitely needs to be fixed...
              • 4. Re: Tree Drag &amp; Drop problem identifying drop location

                Hi guys,


                I ran into the same issue and think I have managed to solve it. Below are the steps I took:


                1. In my dragDrop event I grabbed the drop index by using tree.calculateDropIndex(event) and created a bindable variable [dropIndex] to store the index number.


                2. I created a separate function [tree_getNewParent] to get the new parent from.


                3. In my dragDrop event (I have also tried this with dragComplete) I added a callLater to the function I created in the previous step. I remembered that I had dramas trying to expand items and the solution I found used callLater as the items weren't yet bound. I assume it is the same case here.


                4. Finally in the separate function I set tree.selectedIndex to equal the index I stored in the dragDrop event. Then to access the new parent I simply did a tree.selectedItem.parent()!


                Mine looks something like this:



                private var dropIndex:Number;


                private function tree_dragDrop(event:DragEvent):void{

                     var dIndex:Number = tree.calcualteDropIndex(event);

                     dropIndex = dIndex;




                private function tree_getNewParent():Object{

                     tree.selectedIndex = dropIndex; 

                     var newParent:Object = new Object();

                     newParent = tree.selectedItem.parent();

                     return newParent;



                Please let me know how you go.