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();
}
不過,我真的很š當我移動一個點時,如何重新繪製線條。也可能有許多線連接到任何一個點。我需要以某種方式註冊哪些線連接到哪個點?我如何根據此重新設置線條?
謝謝