as制作可拖动单元格的菜单

2015-08-18 15:22:29来源:作者:人点击

 单元格是可以拖动的,并且可以在三个List之间拖动,不过没加自动滚动来着。AS相当简单,三个List组件分别是list1、list2、list3,然后把所有代码copy到第一帧就可以了。
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);
}

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台