Use DragManager Class and define your own format
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
<mx:Script>
import mx.core.DragSource;
import mx.core.IUIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
private function mouseDownHandler( evt:MouseEvent ):void
{
var initiator:IUIComponent = evt.currentTarget as IUIComponent;
var dragSource:DragSource = new DragSource();
dragSource.addData( initiator, "box");
DragManager.doDrag( initiator, dragSource, evt );
}
private function dragEnterHandler( evt:DragEvent ):void
{
if( evt.dragSource.hasFormat( "box") )
{
DragManager.acceptDragDrop( Canvas( evt.currentTarget ) );
}
}
private function dropHandler( evt:DragEvent ):void
{
var box:Box = Box( evt.dragInitiator );
box.x = evt.localX;
box.y = evt.localY;
}
</mx:Script>
<mx:Canvas id="canvas" backgroundColor="0x0000FF" width="300" height="300" dragEnter="dragEnterHandler(event);" dragDrop="dropHandler(event);">
<mx:Box id="dragItem" width="100" height="100" backgroundColor="0x00FF00" mouseDown="mouseDownHandler(event);"/>
</mx:Canvas>
</mx:Application>
Related examples in the same category