Connecting two buttons with a line

Take a look at my file, I have two buttons and I want them to be connecting with a dynamic line. When the button move, I want the line to still be connected. How do I do this?

Thanks
-Dean

Hold on a minute mate and I’ll attach an FLV.

OK, hopefully you can work out how this works for yourself but if you can’t, don’t hesitate to ask me. One thing I had to break away from is that this only works if your two objects are MOVIECLIPS, not buttons. You could remedy your case by creating the buttons as usual and then selecting the button, hit F8 and choose a name and MOVIECLIP.

Sorry, forgot the attachment. Here it is…

hey thanks a lot man! Ok so can I just take the code from “scriptloop” and paste in into my movie? How does the line know what to connect itself to? Will this work with more than 2 mcs? Thanks man!!!

-Dean

The process is…

  1. Create your two movieclips and give them instance names
  2. Create a 45 degree line that’s 100X100 with the registration point at the top left
  3. Convert the line to a movieclip, right-click on it in the library, select “Export for Actionscript” and enter a name like “line”.
  4. Create a new movieclip (Control+F8) but don’t put anything in it.
  5. Back in the root timeline, create a new layer and put your blank movieclip in it.
  6. Enter that code I gave you into it (you can’t just enter that code into your root timeline as it needs to be looping over and over again)

And that’s basically it. As for how it knows what to connect to, Flash seems to do this as if by magic! Here’s how…

  1. You set the line on the first point (button1’s x and y values in this case)
  2. You resize the line’s width and height to be the distance between your first point and the second/destination point.

Remember: When you draw your line, you HAVE to choose the “Hairline” option for the line’s stroke otherwise the stroke will get bigger and weird stuff will happen the farther away the two points are (try setting the line stroke width to something other than hairline and you’ll see what I mean).

As to your second point, if you want to draw another line, you can just copy the code from the blank movieclip again but change the number “1” in the attachMovie line (the depth) otherwise your second line will just replace the first one you’ve drawn.

Phew! Hope this helps…

wow thanks a lot man! What a lifesaver! Does the line HAVE to start in a 45 degree angle though? Because that is really annoying…

-Dean

crap! I can’t get it to work with the buttons I have!!! I think I just need someone to do it for me because I don’t really know how to code or use flash at all.

-Dean

OK, post the Flash file and I’ll do it. And about the line-you draw it at first, convert it to movieclip etc and then delete it from your stage so it isn’t actually on the stage when your movie starts, it’s just in your library.

Anyways, upload your FLA and I’ll have a look…