# Drawing lines with ActionScript

**URL:** <https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665>\
**Category:** flash\
**Created:** [May 9, 2002, 3:59am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665 "2002-05-09T03:59:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 3:59am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/1 "2002-05-09T03:59:26Z")

</div>

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).](http://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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 4:06am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/2 "2002-05-09T04:06:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 10:08am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/3 "2002-05-09T10:08:49Z")

</div>

…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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 10:22am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/4 "2002-05-09T10:22:53Z")

</div>

What a team. 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 5:34pm UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/5 "2002-05-09T17:34:07Z")

</div>

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:

```auto
 
_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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 9, 2002, 6:31pm UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/6 "2002-05-09T18:31:57Z")

</div>

sweet… I can’t wait to upgrade

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 14, 2002, 12:01am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/7 "2002-05-14T00:01:56Z")

</div>

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

pom 0]

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 14, 2002, 3:30am UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/8 "2002-05-14T03:30:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 14, 2002, 4:15pm UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/9 "2002-05-14T16:15:21Z")

</div>

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. ; )

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 14, 2002, 6:35pm UTC](https://forum.kirupa.com/t/drawing-lines-with-actionscript/2665/10 "2002-05-14T18:35:49Z")

</div>

🙂
