When
a user drags a clipboard item into the bounds of a visual component,
the component dispatches
nativeDragEnter
and
nativeDragOver
events. To
determine whether the component can accept the clipboard item, the handlers
for these events can check the
clipboard
and
allowedActions
properties
of the event object. To signal that the component can accept the
drop, the event handler must call the
NativeDragManager.acceptDragDrop()
method,
passing a reference to the receiving component. If more than one
registered event listener calls the
acceptDragDrop()
method,
the last handler in the list takes precedence. The
acceptDragDrop()
call
remains valid until the mouse leaves the bounds of the accepting
object, triggering the
nativeDragExit
event.
If more than one action is
permitted in the
allowedActions
parameter passed
to
doDrag()
, the user can indicate which of the
allowed actions they intend to perform by holding down a modifier
key. The drag manager changes the cursor image to tell the user
which action would occur if they completed the drop. The intended
action is reported by the
dropAction
property of
the NativeDragEvent object. The action set for a drag gesture is
advisory only. The components involved in the transfer must implement
the appropriate behavior. To complete a move action, for example,
the drag initiator might remove the dragged item and the drop target
might add it.
Your
drag target can limit the drop action to one of the three possible
actions by setting the
dropAction
property of NativeDragManager
class. If a user tries to choose a different action using the keyboard, then
the NativeDragManager displays the
unavailable
cursor. Set
the
dropAction
property in the handlers for both
the
nativeDragEnter
and the
nativeDragOver
events.
The
following example illustrates an event handler for a
nativeDragEnter
or
nativeDragOver
event.
This handler only accepts a drag-in gesture if the clipboard being
dragged contains text-format data.
import flash.desktop.NativeDragManager;
import flash.events.NativeDragEvent;
public function onDragIn(event:NativeDragEvent):void{
NativeDragManager.dropAction = NativeDragActions.MOVE;
if(event.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){
NativeDragManager.acceptDragDrop(this); //'this' is the receiving component
}
}