# Drawing a line over 12 frames

**URL:** <https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944>\
**Category:** Uncategorized\
**Created:** [April 9, 2006, 2:27pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944 "2006-04-09T14:27:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvg](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@nvg](https://forum.kirupa.com/u/nvg)\
**Post date:** [April 9, 2006, 2:27pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/1 "2006-04-09T14:27:07Z")

</div>

[FONT=Arial]Hi all,[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]I was looking for tutorials on drawing in flash using actionscript and all of the tutorials I found showed how to create content instantly (with the click of a button etc).[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]But I was wondering if it was possible to use actionscript to draw a line from coordinate A to B over, say 12 frames?[/FONT]  
[FONT=Arial] [/FONT]  
[FONT=Arial]Can anyone help me out?[/FONT]

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 9, 2006, 4:11pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/2 "2006-04-09T16:11:58Z")

</div>

Sure =)

```auto
function drawLine(x1:Number, y1:Number, x2:Number, y2:Number, duration:Number, target:MovieClip) {
	var counter:Number = 1;
	var width:Number = x2-x1;
	var height:Number = y2-y1;
	var curX:Number = x1;
	var curY:Number = y1;
	var stepX:Number = width/duration;
	var stepY:Number = height/duration;
	target.lineStyle(1, 0x00ff00, 100);
	target.moveTo(curX, curY);
	curX += stepX;
	curY += stepY;
	this.onEnterFrame = function() {
		target.lineTo(curX, curY);
		curX += stepX;
		curY += stepY;
		if (counter == duration) {
			delete this.onEnterFrame;
		}
		counter++;
	};
}
// draws line in current MC
// from 50,50 to 100,200 during 30 frames
drawLine(50, 50, 100, 200, 30, this);

```

---

<div class="post-metadata">

**Author:** ![nvg](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@nvg](https://forum.kirupa.com/u/nvg)\
**Post date:** [April 9, 2006, 4:50pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/3 "2006-04-09T16:50:23Z")

</div>

awsume!

thats exactly what i needed, thanks mathew.er!

C:-)

how could i modifiy that so that i could draw from frame 12 to frame 24?

thanks again for help

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 9, 2006, 5:13pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/4 "2006-04-09T17:13:32Z")

</div>

Call it at frame 12. 😉

---

<div class="post-metadata">

**Author:** ![nvg](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@nvg](https://forum.kirupa.com/u/nvg)\
**Post date:** [April 9, 2006, 5:23pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/5 "2006-04-09T17:23:35Z")

</div>

lol, didnt even cross my mind to do that, thanks again :thumb:

---

<div class="post-metadata">

**Author:** ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)\
**Post date:** [April 9, 2006, 5:38pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/6 "2006-04-09T17:38:18Z")

</div>

LOL :m2:

---

<div class="post-metadata">

**Author:** ![nvg](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@nvg](https://forum.kirupa.com/u/nvg)\
**Post date:** [April 11, 2006, 12:33pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/7 "2006-04-11T12:33:19Z")

</div>

[FONT=Arial]i’m trying to use the function to draw two lines at the same time by calling it in different layers but the same frame, however i’m getting some funny results and can’t figure out why?

[COLOR=black]also i can’t make it draw a line after the other has finished e.g. call it in layer 1 frame 1 with a duration of 12 and then in layer 2 frame 13, [/COLOR]  
[COLOR=black]ne ideas?[/COLOR][/FONT]

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 13, 2006, 1:57pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/8 "2006-04-13T13:57:36Z")

</div>

I reworked that function and now it is a MC’s prototype… that means that you can call it for any Movieclip instance as McInstanceName.drawLine(parameters). First 4 parameters are start and end point coordinates, then its duration in frames, color (in hex i.e. 0xccff6e), thickness of the line and its opacity from 0 to 100.

```auto
MovieClip.prototype.drawLine = function(x1:Number, y1:Number, x2:Number, y2:Number, duration:Number, color:Number, thickness:Number, alpha:Number):Void {
	var counter:Number = 1;
	var lineWidth:Number = x2-x1;
	var lineHeight:Number = y2-y1;
	var curX:Number = x1;
	var curY:Number = y1;
	var stepX:Number = lineWidth/duration;
	var stepY:Number = lineHeight/duration;
	this.lineStyle(thickness, color, alpha);
	this.moveTo(curX, curY);
	curX += stepX;
	curY += stepY;
	this.onEnterFrame = function() {
		this.lineTo(curX, curY);
		curX += stepX;
		curY += stepY;
		if (counter == duration) {
			delete this.onEnterFrame;
		}
		counter++;
	};
};

```

note: It is not possible to draw two lines at time into one MC. If you try to do so, it will stop drawing one and start drawing the other line.

---

<div class="post-metadata">

**Author:** ![nvg](https://avatars.discourse-cdn.com/v4/letter/n/e9bcb4/32.png) [@nvg](https://forum.kirupa.com/u/nvg)\
**Post date:** [April 14, 2006, 8:22pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/9 "2006-04-14T20:22:58Z")

</div>

[COLOR=black][FONT=Arial]absolute legend,[/FONT][/COLOR]

[COLOR=black][FONT=Arial]thankyou so much and sorry to have taken up so much of your time. [/FONT][/COLOR]

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 14, 2006, 8:31pm UTC](https://forum.kirupa.com/t/drawing-a-line-over-12-frames/184944/10 "2006-04-14T20:31:13Z")

</div>

I’m allways glad to help =)
