A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Drag and Drop Objects with Line Between

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    18

    Drag and Drop Objects with Line Between

    Hey all, I'm new here.

    I was wondering if there was anyway to put a line between two or more dragable objects...
    The only example I can think of is metroidprime.com.

    Thanks,
    Adanufgail

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Maybe you need to draw a picture then, cause I'm really not sure what you're asking for...

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    18
    Basicly I'm looking for a way to have objects be draggable but keep a line (which I guess could be an object too) stretched in between them.


  4. #4
    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();
    }


  5. #5
    Junior Member
    Join Date
    Oct 2004
    Posts
    18
    Yay! Thanks!
    I tried to put a button inside the movie clip, but it doesn't seem to work...Any ideas?

  6. #6
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    You tried to put a button inside which movieclip? The line?

    Did you get the basic line drawing and dragging to work?

  7. #7
    Junior Member
    Join Date
    Oct 2004
    Posts
    18
    I got the basic line/drag to work.
    I tried to put a button in the mc movieclip. I'm basicly building this little web of related items and when you click on an item, it pops open a window.

  8. #8
    Junior Member
    Join Date
    Oct 2004
    Posts
    18
    Also, while I'm asking,
    Is there anyway to get a movie clip (one that looks like a book, which I've designed already) to pop up after a button press and based on which button it is, put a specific text file in the book?

  9. #9
    </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