flex树结构--实现树型结构的拖拽

转载请注明来源: 冰树之家 http://blog.csdn.net/zzr173

function doDragEnter(event):Void
{
dragInProgress = true; //自动滚动
event.handled = "true";
}

function doDragExit(event):Void {
event.target.hideDropFeedback();
}

function doMouseMove():Void //自动滚动函数
{
if (dragInProgress) {
if (mouseY + 10 > sortTree.y + sortTree.height)
sortTree.vPosition++;
else if (mouseY - 10 < sortTree.y)
sortTree.vPosition--;
}
}

function doTreeDragOver(event) {
// Do our own drop indicator.
var i : Number;
var dest = event.target;
var parent = event.target.getDropParent();
var node = parent.getTreeNodeAt(dest.getDropLocation() - 1);
dest.rows[previousRow].setState("normal", true);
if (node != undefined && dest.getIsBranch(node)) {
dest.setIsOpen(node, true); // Importtant to make the whole thing work, or we can't get the child.
i = dest.getDisplayIndex(node);
}
else {
i = dest.getDisplayIndex(parent);
}
dest.rows[i].setState("selected", false);

//event.target.showDropFeedback();
if (Key.isDown(Key.CONTROL)) {
event.action = DragManager.COPY;
}
else {
event.action = DragManager.MOVE;
}
previousRow = i;
}

function doTreeDragDrop(event) {
doDragExit(event);
var dragItems;
for (var i = 0; i < event.dragSource.formats.length; i ++) {
var format = event.dragSource.formats[i];
if (event.dragSource.hasFormat(format)) {
dragItems = event.dragSource.dataForFormat(format);
break;
}
}
var dest = event.target;
var dropLoc = dest.getDropLocation();
var destParentNode = dest.getDropParent();

//has to be used when shift dragging (copy) a node;
//dest.clearSelected();

dragItems.reverse();
var destNode = destParentNode.getTreeNodeAt(dropLoc - 1);
for (var i = 0; i < dragItems.length; i++)
{
if (destNode != undefined && dest.getIsBranch(destNode)) {
destNode.addTreeNode(dragItems[i]);
}
else {
destParentNode.addTreeNodeAt(dropLoc, dragItems[i]);
}
}
}

function doDragComplete(event):Void {
dragInProgress = false;
doDragExit(event);
var src = event.target;
if (event.action == DragManager.MOVE) {
var items = src.selectedIndices;
items.sort(sortByNumber);
items.reverse();
for(var i = 0; i < items.length; i++) {
src.removeItemAt(items[i]);
}
}
}

这些函数没多少时间给大家一个详解

但名字已经很明确

有兴趣自己详细看看

你可能感兴趣的:(.net,Flex,Blog)