8-bit mate
8-bit mate

Reputation: 85

Drawing a line from point to point in ActionScript3.0

Lets say I have two objects, and I want to use action script to draw a line connecting them, which will update automatically as they are moved/ dragged. Can anyone show me how to do that, and also how to control line's parameters like colour, weight etc? Any answer would be highly appreciated!

Upvotes: 1

Views: 2789

Answers (1)

Kodiak
Kodiak

Reputation: 5978

Let's say your two movieclips mc1and mc2 share the same parent: mcParent on an ENTER_FRAME event you would do:

mcParent.graphics.clear();
mcParent.graphics.lineStyle(1, 0, 1);
mcParent.graphics.moveTo(mc1.x, mc1.y);
mcParent.graphics.lineTo(mc2.x, mc2.y);

You can change the aspect of the stroke by changing the parameters of lineStyle.

Cheers!

Upvotes: 2

Related Questions