List 拖动数据 for Flex
在Flex中List的数据拖动只需要设置以下几个属性就行了.
dragEnabled="true" dragMoveEnabled="true" dropEnabled="true"
例:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.listClasses.ListItemRenderer;
import mx.collections.ArrayCollection;
import comm.*;
import mx.controls.Alert;
import mx.events.SliderEvent;
[Bindable]
private var carArray : ArrayCollection = new ArrayCollection();
private var db:XML=
<object>
<car>
<Name>wubiyu</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu1</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu2</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu3</Name>
<Available>true</Available>
</car>
</object>
private function init():void
{
var car : CarVO = new CarVO();
car.Name = "Ford";
car.Available = true;
carArray.addItem(car);
car = new CarVO();
car.Name = "Benz";
car.Available = true;
carArray.addItem(car);
car = new CarVO();
car.Name = "BMW";
car.Available = true;
carArray.addItem(car);
//List1.dataProvider = ['wubiyu1','wubiyu2','wubiyu3','wubiyu4','wubiyu5'];
//List2.dataProvider = [];
}
private function btn(e:Event):void
{
var ar:ArrayCollection = List2.dataProvider as ArrayCollection;
for(var i:int =0;i<ar.length;i++)
{
Alert.show(ar.getItemAt(i).Name);
}
}
private function changeHandler(event:Event):void
{
//List1.dataProvider
}
private function List2_Change(e:Event):void
{
Alert.show("dddd");
}
]]>
</mx:Script>
<mx:List x="10" y="0" dragEnabled="true" id="List1" allowMultipleSelection="true"
dropEnabled="true" dragMoveEnabled="true" width="200" dataProvider="{db.children()}" labelField="Name"></mx:List>
<mx:List x="218" y="0" dragEnabled="true" id="List2" dropEnabled="true"
dragMoveEnabled="true" allowMultipleSelection="true" change="List2_Change(event)"
width="200" labelField="Name"></mx:List>
<mx:Button x="156" y="177" label="Button" click="btn(event)"/>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.controls.listClasses.ListItemRenderer;
import mx.collections.ArrayCollection;
import comm.*;
import mx.controls.Alert;
import mx.events.SliderEvent;
[Bindable]
private var carArray : ArrayCollection = new ArrayCollection();
private var db:XML=
<object>
<car>
<Name>wubiyu</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu1</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu2</Name>
<Available>true</Available>
</car>
<car>
<Name>wubiyu3</Name>
<Available>true</Available>
</car>
</object>
private function init():void
{
var car : CarVO = new CarVO();
car.Name = "Ford";
car.Available = true;
carArray.addItem(car);
car = new CarVO();
car.Name = "Benz";
car.Available = true;
carArray.addItem(car);
car = new CarVO();
car.Name = "BMW";
car.Available = true;
carArray.addItem(car);
//List1.dataProvider = ['wubiyu1','wubiyu2','wubiyu3','wubiyu4','wubiyu5'];
//List2.dataProvider = [];
}
private function btn(e:Event):void
{
var ar:ArrayCollection = List2.dataProvider as ArrayCollection;
for(var i:int =0;i<ar.length;i++)
{
Alert.show(ar.getItemAt(i).Name);
}
}
private function changeHandler(event:Event):void
{
//List1.dataProvider
}
private function List2_Change(e:Event):void
{
Alert.show("dddd");
}
]]>
</mx:Script>
<mx:List x="10" y="0" dragEnabled="true" id="List1" allowMultipleSelection="true"
dropEnabled="true" dragMoveEnabled="true" width="200" dataProvider="{db.children()}" labelField="Name"></mx:List>
<mx:List x="218" y="0" dragEnabled="true" id="List2" dropEnabled="true"
dragMoveEnabled="true" allowMultipleSelection="true" change="List2_Change(event)"
width="200" labelField="Name"></mx:List>
<mx:Button x="156" y="177" label="Button" click="btn(event)"/>
</mx:Application>