Peter THANK YOU! I have been looking at this for too long. I was totally
aware of the dragMoveEnabled property, but thought it had to be set to false
to override the default functionality. As it turns out, only dropEnabled
should be set to false. Viola, it works. How can I thank you? You're the
best.

Rachel

On 1/9/07, Peter Watson <[EMAIL PROTECTED]> wrote:

 Try setting dragMoveEnabled='true" for the tileList






http://livedocs.macromedia.com/flex/2/langref/mx/controls/listClasses/ListBase.html



dragMoveEnabled

property



dragMoveEnabled:Boolean<http://livedocs.macromedia.com/flex/2/langref/Boolean.html>
  [read-write]


A flag that indicates whether items can be moved instead of just copied
from the control as part of a drag-and-drop operation. If true, and the
dragEnabled property is true, items can be moved. Often the data provider
cannot or should not have items removed from it, so a MOVE operation should
not be allowed during drag-and-drop.

The default value is false.



regards,

peter
 ------------------------------

*From:* [email protected] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Rachel Maxim
*Sent:* Tuesday, January 09, 2007 3:28 PM
*To:* [email protected]
*Subject:* Re: [flexcoders] Drag and Drop within TileList - why does my
code copy instead of move?



Hi Stephen

I'm not gonna argue with you since you work for Adobe :)

I did figure out shortly after posting that the DragManager.NONE line
wasn't doing anything (I just didn't want to allow drag and drop in that
case).

As far as calling ShowFeedback for every item dragged, I don't see another
way to check against each object in the items array. In my case I'm not
allowing selection of multiples, so "items" is an 1-length array. Perhaps
I'm copying code without really understanding it...do I not need to use
Array for the data format?

Sorry I'm such a noob at this, not much OO development experience here
outside AS2!
Rachel

On 1/9/07, *Stephen Gilson* < [EMAIL PROTECTED]> wrote:

I did not run the code, but two things jump out at me.



In your doDragEnter event, you have this:



                    else
                    {
                        DragManager.NONE;
                    }

DragManager.NONE is a constant, and I'm not sure what you are trying to
do.



In doDragOver(), you are calling showFeedback() on every item dragged. I
think you only need to call this once, based on whether you want to do a
move or a copy.



Hope that helps,


Stephen




 ------------------------------

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





Reply via email to