Drawing lines with ActionScript

I am trying to figure out how to draw a line between two coordinates using ActionScript, the way they do in the Soda Constructor (sodaplay.com/constructor/index.htm)..)

So far the only way I can find is to make a movie clip of a diagonal line, duplicate it at runtime, and then position, stretch, and resize the new line. The problem with this is the line doesn’t have a consistent width, and gets fuzzy when stretched too much.

Does anybody have any ideas?

I dont’ have the code in front of me… but the way most people do it is this.

the line should be made diagonal, and should disect a 100 by 100 square area. Make it with a line size of “hairline” and it wont distort when you stretch it.

Other than that… I’d have to look up the way of actually placing it… but that’s the basics of the line. I guess it’s 100/100 so that you can set it’s scale based upon a 100 pixel size.

…and the code looks sorta like this:

onClipEvent(enterFrame) {
oldx = x;
x = _root._xmouse;
oldy = y;
y = _root._ymouse;
_xscale = x-oldx;
_yscale = y-oldy;
}

put this code in the line movieclip, after following upuat’s directions.:lol:

What a team. :wink:

of course mx includes ways to draw lines completely programatically (hooray!)

have a look at lineTo, moveTo, and lineStyle. they’re all methods of the MovieClip object.

here’s the code example from the manual:

 
_root.createEmptyMovieClip ("triangle", 1);
&nbsp &nbsp &nbsp &nbsp with (_root.triangle){
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp beginFill (0x0000FF, 50);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp lineStyle (5, 0xFF00FF, 100);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp moveTo (200, 200);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp lineTo (300, 300);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp lineTo (100, 300);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp lineTo (200, 200);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp endFill();
}

strictly speaking, that last lineTo isn’t necessary since endFill will close whatever shape’s being drawn anyhow.

sweet… I can’t wait to upgrade

Dammit ! I wrote a tutorial about that, Supra !!

pom 0]

PS : Hairline is the key if I understood the question…

yeah… a lot of people forget to set the stroke for “hairline”. It’s the only way to keep it from scaling thickness.

tell me about it. i wrote a routine to fill shapes, it was montrously complicated and took nearly two weeks, now you go beginFill(), lineTo(), lineTo(), endFill().

bastards. ; )

:slight_smile: