<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.managers.DragManager;
import mx.collections.ArrayCollection;
import mx.core.*;
import mx.events.DragEvent;
import mx.controls.Alert;
import mx.events.ListEvent;
private var i:int=0;
[Bindable]
private var targetData:ArrayCollection=new ArrayCollection();
/**
* 拖动Label控件
*/
private function dragTest(initiator:Label,myData:String,event:MouseEvent,format:String):void{
var ds:DragSource=new DragSource();
ds.addData(myData,format);
mx.managers.DragManager.doDrag(initiator,ds,event);
}
/**
* 接受Label控件
*/
private function testDragEnter(event:DragEvent,format:String):void{
mx.managers.DragManager.acceptDragDrop(IUIComponent(event.target));
}
/**
* 添加Label数据到List
*/
private function testDragDrop(event:DragEvent,format:String):void{
i++;
var myData:Object=new Object();
myData=event.dragSource.dataForFormat(format);
listTarget.dataProvider.addItem(myData + String(i));
}
private function listTarget_changeHandler(event:ListEvent):void{
Alert.show(String(event.target.selectedItem));
}
]]>
</mx:Script>
<mx:Label id="dragLabel" text="Drag the label" x="441" y="47" mouseDown="dragTest(dragLabel,'This is the data.',event,'StringFormat')"/>
<mx:List id="listTarget" width="255" change="listTarget_changeHandler(event)" dataProvider="{targetData}" x="385" y="73" dragEnter="testDragEnter(event,'StringFormat')" dragDrop="testDragDrop(event,'StringFormat')"/>
</mx:Application>
拖放功能
最新推荐文章于 2024-01-06 20:40:53 发布