13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Drag and drop in AIR<br />

Starting a drag-out operation<br />

Adobe AIR 1.0 and later<br />

To start a drag operation, call the NativeDragManager.doDrag() method in response to a mouse down ev<strong>en</strong>t. The<br />

doDrag() method is a static method that takes the following parameters:<br />

Parameter Description<br />

initiator The object from which the drag originates, and which dispatches the dragStart and dragComplete<br />

ev<strong>en</strong>ts. The initiator must be an interactive object.<br />

clipboard The Clipboard object containing the data to be transferred. The Clipboard object is refer<strong>en</strong>ced in the<br />

NativeDragEv<strong>en</strong>t objects dispatched during the drag-and-drop sequ<strong>en</strong>ce.<br />

dragImage (Optional) A BitmapData object to display during the drag. The image can specify an alpha value. (Note:<br />

Microsoft Windows always applies a fixed alpha fade to drag images).<br />

offset (Optional) A Point object specifying the offset of the drag image from the mouse hotspot. Use negative<br />

coordinates to move the drag image up and left relative to the mouse cursor. If no offset is provided, the top,<br />

left corner of the drag image is positioned at the mouse hotspot.<br />

actionsAllowed (Optional) A NativeDragOptions object specifying which actions (copy, move, or link) are valid for the drag<br />

operation. If no argum<strong>en</strong>t is provided, all actions are permitted. The DragOptions object is refer<strong>en</strong>ced in<br />

NativeDragEv<strong>en</strong>t objects to <strong>en</strong>able a pot<strong>en</strong>tial drag target to check that the allowed actions are compatible<br />

with the purpose of the target compon<strong>en</strong>t. For example, a “trash” compon<strong>en</strong>t might only accept drag<br />

gestures that allow the move action.<br />

The following example illustrates how to start a drag operation for a bitmap object loaded from a file. The example<br />

loads an image and, on a mouseDown ev<strong>en</strong>t, starts the drag operation.<br />

package<br />

{<br />

import flash.desktop.NativeDragManager;<br />

import mx.core.UICompon<strong>en</strong>t;<br />

import flash.display.Sprite;<br />

import flash.display.Loader;<br />

import flash.system.LoaderContext;<br />

import flash.net.URLRequest;<br />

import flash.geom.Point;<br />

import flash.desktop.Clipboard;<br />

import flash.display.Bitmap;<br />

import flash.filesystem.File;<br />

import flash.ev<strong>en</strong>ts.Ev<strong>en</strong>t;<br />

import flash.ev<strong>en</strong>ts.MouseEv<strong>en</strong>t;<br />

public class DragOutExample ext<strong>en</strong>ds UICompon<strong>en</strong>t Sprite {<br />

protected var fileURL:String = "app:/image.jpg";<br />

protected var display:Bitmap;<br />

private function init():void {<br />

loadImage();<br />

}<br />

private function onMouseDown(ev<strong>en</strong>t:MouseEv<strong>en</strong>t):void {<br />

var bitmapFile:File = new File(fileURL);<br />

var transferObject:Clipboard = createClipboard(display, bitmapFile);<br />

NativeDragManager.doDrag(this,<br />

transferObject,<br />

display.bitmapData,<br />

Last updated 6/6/2012<br />

610

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!