This appears to be a known limitation of using drag/drop with XML and
move.
 
XML objects have parent pointers that mess up the XMLList.  You have to
remove from the source before adding to the destination.  The default
code does the opposite.
 
This seems to work for me.
 
private function xmlDragComplete(event:Event):void
{
 event.preventDefault();
}
 
private function xmlDragDrop(event:DragEvent):void
{
 event.preventDefault();
 
 var dest:List = event.target as List;
 
    if (event.dragSource.hasFormat("items"))
    {
        var items:Array = event.dragSource.dataForFormat("items") as
Array;
  var dropIndex:int = dest.calculateDropIndex(event);
     dest.hideDropFeedback(event);
 
  var source:List = event.dragInitiator as List;
  var indices:Array = source.selectedIndices;
  var iterator:IViewCursor = source.dataProvider.createCursor();
  indices.sort(Array.NUMERIC);
  var n:int = indices.length;
  for (var i:int = n - 1; i >= 0; i--)
  {
   iterator.seek(CursorBookmark.FIRST, indices[i]);
   iterator.remove();
  }
  source.selectedIndex = -1;
 
  iterator = dest.dataProvider.createCursor();
        iterator.seek(CursorBookmark.FIRST, dropIndex);
        for (i = items.length - 1; i >= 0; i--)
        {
            iterator.insert(items[i]);
        }
    }
}
 
]]>
</mx:Script>
 
<mx:List x="97" y="135" id="leftList" dataProvider="{leftXML.data}" 
height="409" dragEnabled="true" dragMoveEnabled="true"
dragComplete="xmlDragComplete(event)"
dropEnabled="true" labelField="@label"></mx:List>
 
<mx:List x="379" y="135" id="rightList" dataProvider="{rightXML.data}" 
height="409" dragEnabled="true" dragMoveEnabled="true"
dragDrop="xmlDragDrop(event)"
dropEnabled="true" labelField="@label"></mx:List>


________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of jasondrubenstein
Sent: Friday, March 30, 2007 10:25 AM
To: [email protected]
Subject: [flexcoders] Re: List dragMoveEnabled problem?



and, if I write code to convert the XML to an ArrayCollection, and
bind to the new ArrayCollections, everything works fine. 

So it seems the problem is when I'm binding to XMLListCollection. 
Binding to an ArrayCollection is behaving as expected. 

This is a workaround, but there shouldn't be a problem when using
XMLListCollections, I'm guessing?

--- code ---
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
layout="absolute" creationComplete="init()">

<mx:Script>
<![CDATA[
import mx.rpc.http.HTTPService;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;

[Bindable]
private var leftXML:XML;
[Bindable]
private var rightXML:XML;

private var rightArray:Array = new Array();
private var leftArray:Array = new Array();

[Bindable]
private var lac:ArrayCollection;
[Bindable]
private var rac:ArrayCollection;

private function init():void{
getE4X();
}

private function getE4X():void{
var feedUrl:String = new
String("file:///C:/TestListMoves/xml/lefthand.xml
<file:///C:/TestListMoves/xml/lefthand.xml> ");
var loader2:HTTPService = new HTTPService();
loader2.method = "POST";
loader2.url = feedUrl;
loader2.resultFormat = "e4x";
loader2.requestTimeout = 10;
loader2.addEventListener(ResultEvent.RESULT, doLeftLoaded);
loader2.send();
}

private function doLeftLoaded(event:ResultEvent):void{
leftXML = new XML(event.result);
var x:XML;
for each (x in leftXML.item){
leftArray.push(x);
} 
lac = new ArrayCollection(leftArray);

loadRight();
}

private function loadRight():void{
var feedUrl:String = new
String("file:///C:/TestListMoves/xml/righthand.xml
<file:///C:/TestListMoves/xml/righthand.xml> ");
var loader2:HTTPService = new HTTPService();
loader2.method = "POST";
loader2.url = feedUrl;
loader2.resultFormat = "e4x";
loader2.requestTimeout = 10;
loader2.addEventListener(ResultEvent.RESULT, doRightLoaded);
loader2.send();
}
private function doRightLoaded(event:ResultEvent):void{
rightXML = new XML(event.result);
var x:XML;
for each (x in rightXML.item){
rightArray.push(x);
} 
rac = new ArrayCollection(rightArray);
}


]]>
</mx:Script>

<mx:List x="97" y="135" id="leftList" dataProvider="{lac}" 
height="409" dragEnabled="true" dragMoveEnabled="true"
dropEnabled="true" labelField="@name"></mx:List>

<mx:List x="379" y="135" id="rightList" dataProvider="{rac}" 
height="409" dragEnabled="true" dragMoveEnabled="true"
dropEnabled="true" labelField="@name"></mx:List>

<mx:Button x="147" y="53" label="trace"
click="trace(leftList.dataProvider + &quot;\n&quot; + leftXML + '\n')"/>

<mx:Button x="427" y="53" label="trace"
click="trace(rightList.dataProvider + &quot;\n&quot; + rightXML +
'\n')"/>

</mx:Application>
-- code--



 

Reply via email to