Welcome, Guest. Please login or register.
Did you miss your activation email?
03 Sep 2010, 17:28:58 UTC
Forum home
+  flexdeveloper.eu Forum
|-+  Flex and ActionScript 3.0
| |-+  ActionScript 3.0 (Moderators: JMWhittaker, Jan K, thewarpedcoder, James)
| | |-+  How do you disable dragCopy?
« previous next »
Pages: [1] Print
Author Topic: How do you disable dragCopy? (Read 1761 times)
suflex
Newbie FD
*
Posts: 15



« on: 07 Sep 2007, 16:06:34 UTC »

Hello

I have a list container with dragable Items. What i like to do is to allow drag and drop but NOT when pressing CTRL and draging. This copies the item in the list contianer and causes all sorts of problem with the data.

I want to know how I can disable the dragCopy?

Thanks
Suflex
Logged
flexy
flexdeveloper.eu
Guru/Addict FD
*****
Posts: 3,199


Recovering Coffee Addict & Adobe Expert


WWW
« Reply #1 on: 08 Sep 2007, 14:21:28 UTC »

I suflex, I had a look at the docs around this, and it seems a tricky one. I would try using a keyboard listener to listen for the control key press; if it's down, stop any dragging actions through DragManager...
Logged

ksatola
Newbie FD
*
Posts: 1


« Reply #2 on: 11 Sep 2007, 07:11:53 UTC »

You cannot make such a change via MXML (if you use Flex) but you can use ActionScript and event listeners to handle that behavior. Here is an example, I hope it helps Smiley

Code:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.DataGrid;
import mx.events.DragEvent;
import mx.managers.DragManager;


private function dragCompleteHandler(event:DragEvent):void {
if(event.action != DragManager.NONE) {
var myGrid:DataGrid = DataGrid(event.dragInitiator);
var myData:ArrayCollection = ArrayCollection(myGrid.dataProvider);
var myItem:Object = event.dragSource.dataForFormat("items")[0];
for(var i:uint = 0; i < myData.length; i++) {
if(myData.getItemAt(i).userID == myItem.userID) {
myData.removeItemAt(i);
break;
}
}
}
}
]]>
</mx:Script>
<mx:HBox width="100%" height="100%">
<mx:Label text="Source A"/>
<mx:DataGrid dropEnabled="true" dragEnabled="true" dragComplete="dragCompleteHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="Surname" dataField="surname"/>
</mx:columns>
<mx:dataProvider>
<mx:ArrayCollection>
<mx:Object userID="0" name="Tom" surname="Black" />
<mx:Object userID="1" name="Alice" surname="White" />
</mx:ArrayCollection>
</mx:dataProvider>
</mx:DataGrid>

<mx:Label text="Source B"/>
<mx:DataGrid dropEnabled="true" dragEnabled="true" dragComplete="dragCompleteHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="Surname" dataField="surname"/>
</mx:columns>
<mx:dataProvider>
<mx:ArrayCollection>
<mx:Object userID="0" name="Kate" surname="Ninio" />
<mx:Object userID="1" name="John" surname="Brown" />
</mx:ArrayCollection>
</mx:dataProvider>
</mx:DataGrid>

</mx:HBox>
</mx:Application>

The dragCompleteHandler() method is invoked when a dragComplete event occurs. The source item is always removed from the source list no matter the dragging was used with or without CTRL key. Note that in this example you can drag items in both directions.

The demo is available here: http://satola.net/2007/09/DragCopyDisabled/DragCopyDisabled.html
« Last Edit: 11 Sep 2007, 07:20:09 UTC by ksatola » Logged

I am going to Adobe MAX 2007 Europe. Meet me there!
Pages: [1] Print
« previous next »
Share this on: Twitter Twitter Del.icio.us del.icio.us Digg Digg
Jump to:

©2006-2010 Flexdeveloper.eu/Jodie O'Rourke. All rights reserved.
Adobe®, Adobe® Flash™, Adobe® AIR™ and Adobe® Flex™ are registered trademarks of Adobe Systems Incorporated in the United States and other countries. All rights reserved.

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC