3 Replies Latest reply on Apr 2, 2009 11:52 AM by Moenizzle

    Tree Manual Drag and Drop

    Moenizzle
      I am trying to implement a tree with drag and drop functionality that:
      1. Doesn't allow a folder/branch to be dragged into another folder/branch
      2. Doesn't allow a non-branch to be dragged out of a branch and into the root

      Essentially, I'm trying to preserve a state that looks like this:

      Folder
      ---Node
      ---Node
      ---Node
      Folder
      ---Node
      ---Node
      ...

      I want the user to be able to re-order folders via drag and drop, swap nodes between folders and re-order nodes within folders, but nothing else.

      In order to do this I'm implementing a manual drag and drop in which I am calculating the drop index like so:

      var index:int = this.calculateDropIndex(event);

      The problem is that the drop index is the same for two situations that would have different drop results:
      1. Where the drop indicator is immediately before a folder
      2. Where the drop indicator is directly over (right through the center) of an open empty folder

      In the first case I'd like to manually insert the item *somewhere above* the folder (at the index) in the tree and in the second case I would like to place the dragged item *inside* the folder.

      Is there any way that I can differentiate between these two cases. Any help would be GREATLY appreciated. Thanks!
        • 1. Tree Manual Drag and Drop
          Moenizzle Level 1
          Well, I've found something that works and it didn't even require me to abandon the automatic drag and drop functionality of the Tree control (though I'm sure it belongs in the "shameless hack" category).

          The calculateDropIndex() method of the Tree class gets its data from the _dropData member of the class. _dropData.parent contains the item--in my case XML--of the index the dropIndicator is pointing to. If it is null, I know that the dropIndicator is in the root and for my purposes that's enough information. I access it from my extended Tree MXML as follows:

          this.mx_internal::_dropData

          Hope this quick fix can be helpful to someone.
          • 2. Re: Tree Manual Drag and Drop
            this.mx_internal::_dropData worked -beautifully-, thank you!

            I'm assuming you can use this syntax to get all private attributes from internal Flex objects?
            • 3. Re: Tree Manual Drag and Drop
              Moenizzle Level 1
              Well, I believe that the mx_internal only works on members declared as mx_internal. ie...

              mx_internal var _dropData:Object;

              I don't think you can use it to grab any old private variable--ie... private var _dropData:Object--but I could be wrong :) I just ran across this syntax somewhere the other day and have yet to investigate it further.