可以在列表中拖拽,复制所拖拽的目标
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationHandler()">
<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;
import mx.events.DragEvent;
import mx.collections.ArrayCollection;
private function creationHandler():void
{
var collection:ArrayCollection = new ArrayCollection(['A','B','C']);
contactList.dataProvider = collection;
}
private function dropHandler(evt:DragEvent):void
{
var listItem:Object = evt.dragSource.dataForFormat('items');
var index:int = contactList.calculateDropIndex(evt);
ArrayCollection(contactList.dataProvider).setItemAt(ObjectUtil.copy(listItem),index);
}
]]>
</mx:Script>
<mx:Panel x="164" y="70" width="430" height="319" layout="absolute">
<mx:List id="contactList" width="100%" height="100%" dragEnabled="true" dropEnabled="true"
dragMoveEnabled="false" dragComplete="dropHandler(event)"/>
</mx:Panel>
</mx:Application>
例子中讲list内联dragEnabled、 dropEnabled的属性设为true,用它们来响应dragManger事件,dragMoveEnabled是用来指示列表中被拖拽的目标是移动到还是复制到列表的标记。默认状态为false,支持将拖拽数据复制添加到列表当中(此处为复制),从而list中接受新的项目,调用ObjectUtil.copy为其制定新的标识符;设为true,则事件放置完成时,列表拖拽的项目会从原来的索引中移动到鼠标指向的目标索引。