3 Replies Latest reply on Nov 17, 2006 9:40 AM by djhall77

    Tree calculatedropindex

    kimbflex Level 1
      Hello,

      I need to get the drop index of a subnode of a tree i.e. if i drop or move a tree item on node 2, subnode 2 I need the drop event to return something like '[1,1]'. CalculateDropIndex() however returns just one value '3' e.g.

      TreeNode 1
      Subnode 1
      Subnode 2
      TreeNode 2
      Subnode 1
      > Subnode 2 <

      Am I doing something wrong or is this a bug?
        • 1. Re: Tree calculatedropindex
          peterent Level 2
          This isn't a bug; the Tree just takes some patience. I'll be posting an article about drag and drop on my blog soon. Here's an example dragDrop event handler that uses calculateDropIndex. You'll notice that as soon as I get the drop index I make that the selectedIndex of the tree. Then I can retrieve that item and get all sorts of information out of it.

          private function onDragDrop( event:DragEvent ) : void
          {
          var ds:DragSource = event.dragSource;
          var dropTarget:Tree = Tree(event.currentTarget);

          var items:Array = ds.dataForFormat("items") as Array;

          var r:int = tree.calculateDropIndex(event);
          tree.selectedIndex = r;
          var node:XML = tree.selectedItem as XML;
          var p:*;

          // if the selected node has children (it is type==city),
          // then add the items at the beginning
          if( tree.dataDescriptor.hasChildren(node) ) {
          p = node;
          r = 0;
          } else {
          p = node.parent();
          }

          for(var i:Number=0; i < items.length; i++) {
          var insert:XML = <node />;
          insert.@label = items ;
          insert.@type = "restaurant";
          tree.dataDescriptor.addChildAt(p, insert, r+i);
          }
          }
          • 2. Re: Tree calculatedropindex
            kimbflex Level 1

            Cheers, that works great.

            kimb

            • 3. Re: Tree calculatedropindex
              djhall77
              This only works when you are dragging over a node. When the drag indicator is between nodes the drop target you get using this method will be the next node in the tree if you laid out all the nodes in linear fashion. If the drag indicator is between nodes underneath a parent node I want to be able to access the parent node.