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>

Reply via email to