I think dataForFormat(“items”) or dataForFormat(“source”), not sure which is valid for Tree, might give you the original items as opposed to the copies.

 

Matt

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Sean McKibben
Sent: Wednesday, July 06, 2005 1:17 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Reorder tree via dragging

 

So I'm trying to make a tree which can reorder its nodes by dragging 
them. One of the things I wanted to do is prevent a parent item from 
being dragged on to any of its children, and to show that during the 
dragOver event.

In order to calculate whether the source is being dragged on to any 
of its offspring, I've been comparing the 
event.dragSource.dataForFormat("treeItems") first to 
firstValue=event.target.getDropParent().getTreeNodeAt
(event.target.getDropLocation()) then recursively to the parents of 
firstValue.

This apparently doesn't work because dataForFormat seems to hand me a 
copy of the items being dragged instead of an actual reference, so 
the two values are never equal. I did note that the items that 
dataForFormat give me, do contain references to the real parents, 
data and other objects, it is just that the items themselves are 
copies for some reason.

What I ended up doing is something like the following:

if(checkParentDrop(myowncustom.TreeUtils.findDataItemNode
(view.TemplateAssemblyTree, dragItems[i].getData())
                , event.target.getDropParent().getTreeNodeAt
(event.target.getDropLocation())))
     action = "">

private function checkParentDrop(source, node):Boolean
     {
         if(source == node)
             return true;
         if(node.getParent()!=null)
             return checkParentDrop(source, node.getParent());
         else
             return false;
     }


public static function findDataItemNode(tree:mx.controls.Tree, 
o:Object):TreeNode
... recursively check the entire tree for the same getData() 
reference ...

So basically instead of comparing items from 
event.dragSource.dataForFormat("treeItems"), i have to recursively 
look them up by the reference they contain to their getData() 
information, to get the actual reference to the TreeNode which I then 
compare to the drop target and its ancestors for referential equality.

This is horribly ugly, but it works. Is there a better way that 
people have stumbled across to validate tree->self drags? I wish that 
dataForFormat handed over references instead of copies!

(sorry if this was discussed before; I'm apparently bad at finding 
previously discussed topics in this list!)

Sean




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





--
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




Reply via email to