A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Drag and Drop Objects with Line Between

Hybrid View

  1. #1
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    This is a frame script. It assumes the blue square and the green square are movieclips that have been assigned the names mc1 and mc2.

    If you want the lines to issue from a particular corner, orient the movieclips so that the crosshairs correspond to that corner.

    I prefer to have the lines issue from the center (so I keep the crosshair centered).

    code:

    _root.createEmptyMovieClip("line_mc", 1);

    MovieClip.prototype.drawLine = function()
    {
    this.clear();
    this.lineStyle(2,0xFF0000,100);
    this.moveTo(mc1._x, mc1._y);
    this.lineTo(mc2._x, mc2._y);
    }

    // insure movieclips are in front of line
    mc1.swapDepths(2);
    mc2.swapDepths(3);

    // draw initial line
    line_mc.drawLine();

    mc1.onPress = mc2.onPress = function()
    {
    this.startDrag();
    line_mc.onEnterFrame = drawLine;
    }

    mc1.onRelease = mc2.onRelease = function()
    {
    delete line_mc.onEnterFrame;
    this.stopDrag();
    }


  2. #2
    </hate> dtone314's Avatar
    Join Date
    Jun 2005
    Location
    CA
    Posts
    262
    How would I go about modifying this code to handle four MCs? I'm imagining something that looks like dragging walls in a room where each MC is a corner of the room. Does that make sense? mc1 connects to mc2 which connects to mc3 which connects to mc4 which connects to mc1 again. Thanks for your help!
    -dtøne-
    Flash CS4 | AS2
    Life is a journey, not a destination.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center