Thanks a lot Alex.. I have commented out the preventDefault() in onDragComplete() and in onDragDrop() and now everything works as expected..
Thanks Mars --- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote: > > If you look at the implementations in Tree.as, you'll see that > dragDropHandler and dragCompleteHandler are special. One or the other > handles the remove and add instead of the default way where dragDrop > adds and dragComplete removes. > > > > That's because we have to remove from XML before adding. So, knowing > that, I think you need a preventDefault() call in onDragDrop > > > > ________________________________ > > From: [email protected] [mailto:[EMAIL PROTECTED] On > Behalf Of sk_acura > Sent: Monday, June 02, 2008 12:59 PM > To: [email protected] > Subject: [flexcoders] Moving Nodes across Trees (with in the tree is > works fine) > > > > Hi All, > > I am trying to have the drag and drop feature acoross two trees in > my app. (the two trees are called source Tree and traget Tree). > > Here i am posting the code below ( i got this from one of the post > in this forum and added a second tree..) > > I can move the items with in the tree without any problems..How > ever i cannot move items from one tree to another..!! > > [CODE] > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml > <http://www.adobe.com/2006/mxml> " > creationComplete="init()" > width="100%" height="100%" layout="absolute" > backgroundColor="white"> > <mx:Script> > <![CDATA[ > import test.Collections; > import mx.managers.CursorManager; > import mx.collections.ItemResponder; > import mx.rpc.AsyncToken; > import mx.rpc.remoting.RemoteObject; > import test.Node; > import test.CollectionBrowserNode; > import mx.controls.List; > import mx.core.DragSource; > import mx.managers.DragManager; > import mx.events.*; > import mx.rpc.events.ResultEvent; > import mx.controls.Alert; > import mx.collections.ArrayCollection; > import mx.utils.ObjectUtil; > > private var sourceArrayCollection:ArrayCollection = null; > > private var targetArrayCollection:ArrayCollection = null; > > public function init():void{ > trace("Here in init() of > RearrangeCollection "); > sourceArrayCollection = new ArrayCollection(); > targetArrayCollection = new ArrayCollection(); > > var collectionList:ArrayCollection = new > ArrayCollection(); > populateChildNodes("Source > Tree",sourceArrayCollection); > populateChildNodes("Target > Tree",targetArrayCollection); > sourceCollectionTree.dataProvider = > sourceArrayCollection; > targetCollectionTree.dataProvider = > targetArrayCollection; > > } > > private function populateChildNodes > (nodeNamePrefix:String,collection:ArrayCollection):void{ > for(var i:int =0;i<5;i++){ > var node:CollectionBrowserNode = new > CollectionBrowserNode(); > node.nodeId =nodeNamePrefix+"-Id["+i+"]"; > node.nodeLabel =nodeNamePrefix+"-Label["+i+"]"; > node.children = new ArrayCollection(); > > var childNode:CollectionBrowserNode = new > CollectionBrowserNode(); > childNode.nodeId =nodeNamePrefix+"child-Id["+i+"]"; > childNode.nodeLabel =nodeNamePrefix+"Child Label > ["+i+"]"; > > node.children.addItem(childNode); > > collection.addItem(node); > } > } > //event for tree Click > private function treeClickHandler(evt:MouseEvent):void{ > var id:String = > [EMAIL PROTECTED]; > var treeType:String = > [EMAIL PROTECTED]; > Alert.show("Here in click Handler"); > } > > public function treeLabel( item:Object ) : String{ > //trace("Here in treeLabel"); > var node:CollectionBrowserNode = > null; > node = CollectionBrowserNode(item); > //trace(" Here in treeLabel and Node > ="+node.className); > return node.nodeLabel; > } > > private function itemSelected():void{ > trace("Here in itemSelected.."); > } > > private function onDragDrop(event : DragEvent) : void > { > var draggedItems : Array = > (event.dragSource.dataForFormat("treeItems") as Array); > for each (var draggedItem : > CollectionBrowserNode in draggedItems) { > var parentTarget : > CollectionBrowserNode = (Tree (event.currentTarget)).getParentItem > (draggedItem); > trace ("onDragDrop", > draggedItems.length); > } > } > > private function onDragComplete(event : DragEvent) : > void { > event.preventDefault(); > var draggedItems : Array = > (event.dragSource.dataForFormat("treeItems") as Array); > for each (var draggedItem : > CollectionBrowserNode in draggedItems) { > var parentTarget : > CollectionBrowserNode = (Tree (event.currentTarget)).getParentItem > (draggedItem); > trace ("onDragComplete", > draggedItems.length); > } > } > > ]]> > </mx:Script> > > <mx:HDividedBox width="100%" height="100%"> > > <mx:VBox verticalAlign="top" > height="100%" width="100%"> > <mx:Tree id="sourceCollectionTree" > labelFunction="treeLabel" > showRoot="true" > width="100%" height="100%" > dragEnabled="true" > dropEnabled="true" > > dragDrop="onDragDrop(event)" > dragComplete="onDragComplete(event)" > > /> > </mx:VBox> > <mx:VBox verticalAlign="top" > height="100%" width="100%"> > <mx:Tree id="targetCollectionTree" > labelFunction="treeLabel" > showRoot="true" > width="100%" height="100%" > dragEnabled="true" > dropEnabled="true" > > dragDrop="onDragDrop(event)" > dragComplete="onDragComplete(event)" > /> > </mx:VBox> > </mx:HDividedBox> > </mx:Application> > > [/CODE] > > CollectionBrowserNode.as > > [CODE] > > package test > { > > public class CollectionBrowserNode extends Node > { > public function CollectionBrowserNode() > { > super(); > } > > public function setNode(node:Node):void{ > if(node!=null){ > this.childElements = > node.childElements; > this.children = node.children; > this.leaf = node.leaf; > this.nodeId = node.nodeId; > this.nodeLabel = node.nodeLabel; > this.parent = node.parent; > this.root = node.root; > } > } > > public var dateCreated:String; > public var propertyHolderMap:Object; > > public override function toString():String{ > return "CollectionBrowserNode[ > nodeId="+nodeId+", nodeLabel="+nodeLabel+"]"; > } > > } > } > [/CODE] > > Node.as > > [CODE] > package test > { > import mx.collections.ArrayCollection; > > public class Node > { > > public var description:String; > > public var nodeId:String; > public var nodeLabel:String; > > public var className:String; > public var root:Boolean; > public var leaf:Boolean; > public var container:Boolean; > public var childElements:ArrayCollection; > public var children:ArrayCollection; > public var parent:Node; > > public function toString():String{ > return "Node[ nodeId="+nodeId+", > nodeLabel="+nodeLabel+"]"; > } > > } > } > [/CODE] > > setting the dragMoveEnabled has no effect. > > Thanks > Mars.. >

