import fl.events.ListEvent;
import fl.controls.List;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
//为组件添加数据
var i:uint = 0;
for(i = 0;i<21;i++){
list1.addItem({label:"label" + i});
}
for(i = 21;i<41;i++){
list2.addItem({label:"label" + i});
}
for(i = 41;i<61;i++){
list3.addItem({label:"label" + i});
}
//添加侦听器
list1.addEventListener(ListEvent.ITEM_ROLL_OVER,itemRollOverHandler);
list2.addEventListener(ListEvent.ITEM_ROLL_OVER,itemRollOverHandler);
list3.addEventListener(ListEvent.ITEM_ROLL_OVER,itemRollOverHandler);
list1.addEventListener(ListEvent.ITEM_ROLL_OUT,itemRollOutHandler);
list2.addEventListener(ListEvent.ITEM_ROLL_OUT,itemRollOutHandler);
list3.addEventListener(ListEvent.ITEM_ROLL_OUT,itemRollOutHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
//标记的组件和相应的行
var lastCaredList: List = null;
var lastCaredIndex:int = -1;
var dragedList: List = null;
var dragedIndex:int = -1;
var itemValue:Object = null;
//单元格渲染器
var cellRendererClass:Class = List.getStyleDefinition()["cellRenderer"];
var cellRenderer:ICellRenderer = new cellRendererClass() as ICellRenderer;
//侦听器
function itemRollOverHandler(event: ListEvent):void{
//标记组件和行
lastCaredList = event.target as List;
lastCaredIndex = event.index;
}
function itemRollOutHandler(event: ListEvent):void{
//取消标记
lastCaredList = null
lastCaredIndex = -1;
}
function mouseDownHandler(event:MouseEvent):void{
if(lastCaredList != null){
//删除标记的行
itemValue = lastCaredList.removeItemAt(lastCaredIndex);
createCellRenderer();
}
}
function mouseUpHandler(event:MouseEvent):void{
if(itemValue){
removeChild(cellRenderer as Sprite);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
//判断,是加到新组件中还是原组件中
if(lastCaredList){
lastCaredList.addItemAt(itemValue,lastCaredIndex);
}else{
dragedList.addItemAt(itemValue,dragedIndex);
}
itemValue = null;
}
}
function mouseMoveHandler(event:MouseEvent):void{
//拖动渲染器
cellRenderer.x = mouseX;
cellRenderer.y = mouseY;
event.updateAfterEvent();
}
function createCellRenderer():void{
dragedList = lastCaredList;
dragedIndex = lastCaredIndex;
//拖动的渲染器
cellRenderer.listData = new ListData(itemValue.label,itemValue.icon,lastCaredList,0,0,0);
cellRenderer.selected = true;
cellRenderer.setSize(lastCaredList.width,lastCaredList.rowHeight);
cellRenderer.x = mouseX;
cellRenderer.y = mouseY;
addChild(cellRenderer as Sprite);
stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
--------------------next---------------------
阅读(426) | 评论(0) | 转发(0) |