1
我有一组显示在画布上的点(的代码密钥比特拉出):闪光灯拖动一个点,并有线,连接的其他点移动
// Drop points based on x y coords
for (var i = 0; i < 50; i++) {
itemPoint[i] = new mcDot();
itemPoint[i].x = 500*Math.random();
itemPoint[i].y = 500*Math.random();
// Set up drag & drop
initDragger(itemPoint[i]);
itemPoint[i].buttonMode = true;
addChild(itemPoint[i]);
}
我然后连接点 - 一个点可以有50个连接
// Draw connections
for (i = 0; i < 50; i++) {
for (j = 0; j < 50; j++) {
// Is there a connection in the matrix?
if (connectMatrix[i][j] > 0) {
itemConnect[k] = new Shape();
itemConnect[k].graphics.lineStyle(1, 0x000000);
// Connect the line to the dots
itemConnect[k].graphics.moveTo(itemPoint[i].x, itemPoint[i].y);
itemConnect[k].graphics.lineTo(itemPoint[j].x, itemPoint[j].y);
addChild(itemConnect[k++]);
}
}
}
我有拖放进行点工作:
/** Drag and drop functions */
function initDragger(mc:MovieClip):void {
mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
mc.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
function mouseDownHandler(e:MouseEvent):void {
e.currentTarget.startDrag();
}
function mouseUpHandler(e:MouseEvent):void {
e.currentTarget.stopDrag();
}
不过,我真的很š当我移动一个点时,如何重新绘制线条。也可能有许多线连接到任何一个点。我需要以某种方式注册哪些线连接到哪个点?我如何根据此重新设置线条?
谢谢