Drag and drop label value to a List
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.core.*;
import mx.managers.DragManager;
import mx.events.DragEvent;
[Bindable]
private var targetData:ArrayCollection = new ArrayCollection();
private function dragTest(initiator:Label, myData:String, event:MouseEvent, format:String):void
{
var ds:DragSource = new DragSource();
ds.addData(myData, format);
DragManager.doDrag(initiator, ds, event);
}
private function listDragEnter(evt:DragEvent, format:String):void
{
DragManager.acceptDragDrop(IUIComponent(evt.target));
}
private function listDragDrop(evt:DragEvent, format:String):void
{
var myData:Object = new Object();
myData = evt.dragSource.dataForFormat(format);
myList.dataProvider.addItem(myData);
}
</mx:Script>
<mx:Label id="dragLabel" text="Drag this Label" mouseDown="dragTest(dragLabel, 'A', event, 'stringFormat')" />
<mx:List id="myList"
dataProvider="{targetData}"
dragEnter="listDragEnter(event, 'stringFormat')"
dragDrop="listDragDrop(event, 'stringFormat')" />
</mx:Application>
Related examples in the same category