Removing the business rules still causes the copy instead of move, it just
doesn't enforce the rules :)
Basically, stripping out all the new functionality and gradually adding it
back in, I have concluded that if I do NOT manually handle any of the drag
and drop, and set the drag properties to true (dragMoveEnabled="true",
dragEnabled="true", dropEnabled="true"), then everything moves as it should,
but I cannot get the data I need out of the drop operation (to call the
remote objects to update the database) . So the problem is clearly in my
drag and drop code, but I am yet unable to locate the problem. Commenting
out various lines of code only results in errors because they are necessary
for the drag and drop to work.
I think the problem might have something to do with this line - I have a
feeling it's duplicating the built-in drag and drop functionality
ListCollectionView(dropTarget.dataProvider).addItemAt(items[i],
dropLoc);
However, if I don't use this method to add the item, then I can't get the
data back out of the item. Does that make any sense?
I'm hoping there is someone who has done this before and can clarify what I
need to do to override the default TileList drag and drop behavior? The docs
seem to only show using the default behavior with lists, with no server-side
component or add'l data manipultion examples.
Thanks
Rachel
On 1/9/07, Tracy Spratt <[EMAIL PROTECTED]> wrote:
If it works without the rules, remove them. Then add them back until it
breaks.
Tracy
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Rachel Maxim
*Sent:* Tuesday, January 09, 2007 1:23 PM
*To:* [email protected]
*Subject:* Re: [flexcoders] Drag and Drop within TileList - why does my
code copy instead of move?
I'm gonna keep working on it, but that is exactly what I am trying to
find! Unfortunately this is pretty bare-bones as far as functionality goes,
so if I remove just a couple lines then the entire drag and drop won't work
:) I'll definitely post when I find the solution though!
R
On 1/9/07, *Tracy Spratt* <[EMAIL PROTECTED]> wrote:
Have you found the line of code that changes the functionality? If not,
do that.
Tracy
------------------------------
*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Rachel Maxim
*Sent:* Tuesday, January 09, 2007 12:49 PM
*To:* [email protected]
*Subject:* [flexcoders] Drag and Drop within TileList - why does my code
copy instead of move?
Hello,
I would really appreciate another set of eyes taking a look at this code
to see what I'm doing wrong. I have several tile lists where tiles can be
dragged and dropped around. This code is pretty much straight out of the
docs plus a few rules, It's working fine except that the tiles are copying,
not moving as I want them to. Before I overrode the default drag-and-drop
functionality, they moved, but when I implemented my rules to ensure they
are being dragged to a list that accepts them, they started copying.
Thanks so much for any help!
Rachel Maxim
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml "
verticalScrollPolicy="auto"
horizontalScrollPolicy="off">
<!-- component properties to identify this item for drag and drop
listeners -->
<mx:String id="userName">{ data.userName}</mx:String>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.List;
import mx.core.DragSource;
import mx.events.DragEvent;
import mx.managers.DragManager;
import mx.containers.Tile;
import mx.collections.IList;
//drag enter handler
private function doDragEnter(event:DragEvent):void {
//drag target - where item is being dragged
var dragInitiator:TileList = TileList(event.currentTarget
);
//dragged items
var items:Array = event.dragSource.dataForFormat("items")
as Array;
for (var i:uint = 0; i < items.length; i ++) {
var fromCaseName:String = items[i].caseName; //the
case name that the deal is being dragged from
var toCaseName:String = data.caseName; //the case name
that the deal is being dragged too
//check to ensure drop is allowed on this object
if (isDropAllowed(fromCaseName, toCaseName))
{
DragManager.acceptDragDrop(dragInitiator);
}
else
{
DragManager.NONE;
}
}
}
private function doDragOver(event:DragEvent):void
{
//dragged items
var items:Array = event.dragSource.dataForFormat("items")
as Array;
for (var i:uint = 0; i < items.length; i ++) {
var fromCaseName:String = items[i].caseName; //the
case name that the deal is being dragged from
var toCaseName:String = data.caseName; //the case name
that the deal is being dragged too
//check to ensure drop is allowed on this object
if (isDropAllowed(fromCaseName, toCaseName))
{
DragManager.showFeedback(DragManager.MOVE);
}
else
{
DragManager.showFeedback (DragManager.NONE);
}
}
}
//drop handler
private function doDragDrop(event:DragEvent):void {
//define the drop target
var dropTarget:TileList = TileList(event.currentTarget);
//dragged items
var items:Array = event.dragSource.dataForFormat("items")
as Array;
//get the drop location in the destination
var dropLoc:int = dropTarget.calculateDropIndex(event);
//loop over dragged items to get data from each
for (var i:uint = 0; i < items.length; i ++) {
trace("The deal " + items[i].caseID + " " +
items[i].companyName + " " + items[i].caseName + " was assigned to " +
userName); //debugging trace
//add to drop target
IList(dropTarget.dataProvider).addItemAt(items[i],
dropLoc);
trace("the deal was dropped at " +
dropTarget.dataProvider.getItemAt(dropLoc).caseName);
}
//once complete, dispatch the drag complete event
var dragComplete:Event = new Event('dragComplete',true);
this.dispatchEvent(dragComplete);
}
//business rules that determine if this object can be dropped
on the intended target
private function isDropAllowed(fromCaseName:String,
toCaseName:String):Boolean {
//if deal is being dragged to the same caseName, drop is
allowed
if (fromCaseName == toCaseName) {
return true;
}
else {
return false;
}
}
]]>
</mx:Script>
<mx:Label text="{data.userName}" top="5" left="5" id="lblCreditName"
fontWeight="bold" width="231" textAlign="left"/>
<mx:TileList dataProvider="{data.userDeals}"
itemRenderer="DealButton"
id="tlDeals"
columnCount="2"
verticalScrollPolicy="auto"
horizontalScrollPolicy="off"
rowCount="0"
rowHeight="40"
columnWidth="160"
maxHeight="80"
direction="horizontal"
allowMultipleSelection="false"
dragEnabled="true"
dragEnter="doDragEnter(event);"
dragOver="doDragOver(event);"
dragDrop="doDragDrop(event);"
paddingBottom="1" paddingTop="1" paddingLeft="1"
paddingRight="1"
left="0" top="25" right="0" bottom="0"
styleName="deal" themeColor="#ffffff"/>
</mx:Canvas>