У меня есть набор точек, отображаемых на холсте (ключевые фрагменты кода извлечены):
// 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();
}
Однако я действительно застрял в том, как перерисовывать линии при перемещении точки. Также может быть много линий, соединенных с одной точкой. Нужно ли как-то регистрировать, какие линии связаны с какой точкой? Как мне перерисовать линии на основе этого?
Спасибо