I just encountered this problem in our app this morning, and I thought
my solution might be helpful for someone out there. Building on
Peter's example (1), I also needed to allow a user to drag a new root
node onto the tree. That is, if they drag onto an existing node, add
it as a child. Otherwise, add it as a root. Below us a sketch of the
doDragDrop function I used. It's a hack, but it works:

private function doDragDrop(e:DragEvent):void {
  var items:Array = e.dragSource.dataForFormat("items") as Array;
  if(e.target == myTree) {
    var tree:Tree = Tree(e.target);
    var i:int = tree.calculateDropIndex(e);
    tree.addEventListener(FlexEvent.VALUE_COMMIT, figureActionOut);
    tree.selectedIndex = i;
    tree.removeEventListener(FlexEvent.VALUE_COMMIT, figureActionOut);
    function figureActionOut(e2:FlexEvent):void {
      if(tree.selectedIndex != i) {
        trace("Add New Root(s)");
      } else {
        trace("Add Child(ren)");
      }
    }
  }                                                     
}                                                               

Hope that helps someone!

Jim

1. 
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid=1209910

On 10/30/06, kim_boulton <[EMAIL PROTECTED]> wrote:
>
> If you skim over to the Adobe Flex 2 General discussion forum. Peter
> Ent just showed me how to get this working.
>
> Easy too.
>
> hth
>
> kimb
>
>
> --- In [email protected], "kim_boulton" <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > Me too!
> >
> > kimb
> >
> > --- In [email protected], "Niklas Richardson"
> > <flexcoldfusion@> wrote:
> > >
> > > Hi there,
> > >
> > > Could you post your example code as I'm just trying to sort this out
> > myself
> > > and running into the same problem.
> > >
> > > Thanks.
> > >
> > > Regards
> > >
> > > Niklas
> > >
> > >
> > >
> > >
> > > On 8/21/06, Jason Y. Kwong <inlineblue@> wrote:
> > > >
> > > >   I had posted a request to Adobe's wish form, asking that the
> > drop data
> > > > be made available.  I got a very quick response (within 10
> minutes!):
> > > >
> > > > "Yes, we discovered this very soon after shipping that this data
> > should
> > > > have been exposed. We have a bug for this already logged
> > internally, so
> > > > we will work on fixing it for the future. For now, I think you
> > will have
> > > > to rewrite your own updateDropData function, which is unfortunate."
> > > >
> > > > So I'll have to stick with my original plan of duplicating a few
> > methods
> > > > (as stated in my original post).
> > > >
> > > >
> > > >
> > > > On 8/21/06, thunderstumpgesatwork <thunder.stumpges@> wrote:
> > > > >
> > > > >    I'm glad it's not just me! So, were you able to get something
> > working
> > > > > for your scenario?
> > > > >
> > > > > Anyone from the Adobe team want to confirm this and/or offer
> > > > > alternative solutions?
> > > > >
> > > > > thanks,
> > > > > Thunder
> > > > >
> > > > > --- In [email protected]
> > <flexcoders%40yahoogroups.com>, "Jason
> > > > > Y. Kwong" <inlineblue@>
> > > > >
> > > > > wrote:
> > > > > >
> > > > > > I've running into this myself right now as well. If you look
> > at the
> > > > > Tree
> > > > > > code, you can see that the "drop parent" is being tracked in the
> > > > > variable
> > > > > > _dropData.parent. It gets calculated in the method
> > updateDropData().
> > > > > > Unfortunately, both the variable and the method are private, so
> > > > > they're
> > > > > > useless as is (another example of Adobe being overly
> private, I'm
> > > > > afraid).
> > > > > > I've had to duplicate (and tweak) the updateDropData() method to
> > > > > make use of
> > > > > > the algorithm. The methods getChildIndexInParent() and
> > > > > getChildren() had to
> > > > > > be duplicated as well.
> > > > > >
> > > > > > On 8/18/06, thunderstumpgesatwork <thunder.stumpges@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > Bump... I'm trying to do similar. Though I need to do it
> in the
> > > > > > > DragOver event, and determine under which node it is going
> to be
> > > > > > > dropped. I need to do this because certain places in the
> > tree are
> > > > > > > acceptable places to drop certain items...
> > > > > > >
> > > > > > > I know I can get the "dropIndex" by using the tree function
> > > > > > > "calculateDropIndex" however this is not enough. It simply
> > tells me
> > > > > > > where in the list of displayed nodes it will go. So if the
> > item is
> > > > > > > being placed between the last item in a lower level node
> and the
> > > > > > > continuation of the next level up, the index is the same,
> > but the
> > > > > > > parent of the ending drop is different.
> > > > > > >
> > > > > > > I can tell the Tree internals are tracking this because
> the drop
> > > > > > > indicator changes it's horizontal alignment to indicate
> > which level
> > > > > > > it's going in...
> > > > > > >
> > > > > > > Anyone know how to determine the parent node of the
> > indicated drop
> > > > > > > position?
> > > > > > >
> > > > > > > thanks,
> > > > > > > Thunder
> > > > > > >
> > > > > > >
> > > > > > > --- In [email protected]
> > <flexcoders%40yahoogroups.com><flexcoders%40yahoog
> > > > > roups.com>,
> > > > >
> > > > > "Jonas
> > > > > > > Windey" <jonas@> wrote:
> > > > > > > >
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I have a tree with drag & drop enabled. Now what is the
> > best way
> > > > > to
> > > > > > > find out
> > > > > > > > where the current selected item is dropped?
> > > > > > > >
> > > > > > > > I'd need to know its parent (if it's not on the rootnode),
> > and the
> > > > > > > position
> > > > > > > > where it's dropped inside that parent.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Or is there an easier way to find the position? Like
> > comparing the
> > > > > > > > dataproviders before & after?
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Thanks for the tips,
> > > > > > > >
> > > > > > > > Jonas
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Niklas Richardson
> > > Prismix Ltd
> > >
> > > UK based Flex and ColdFusion Specialists
> > >
> >
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to