views:

417

answers:

1

Hi,

I have a set of dots displayed on the canvas (key bits of code pulled out):

// 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]);
}

I then connect the dots - one dot could have 50 connections

// 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++]);
     }
    }
}

I have drag and drop working for the dot:

/** 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();
}

However, I am really stuck on how to redraw the lines as I move a dot. Also there could be many lines connected to any single dot. Do I need to somehow register which lines are connected to which dot? How do I redrew the lines based on this?

Thanks

+1  A: 
bhups