# Newbie about animating a line in actionscript

**URL:** <https://forum.kirupa.com/t/newbie-about-animating-a-line-in-actionscript/65078>\
**Category:** Uncategorized\
**Created:** [September 22, 2004, 9:14pm UTC](https://forum.kirupa.com/t/newbie-about-animating-a-line-in-actionscript/65078 "2004-09-22T21:14:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hendersson](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hendersson](https://forum.kirupa.com/u/hendersson)\
**Post date:** [September 22, 2004, 9:14pm UTC](https://forum.kirupa.com/t/newbie-about-animating-a-line-in-actionscript/65078/1 "2004-09-22T21:14:08Z")

</div>

hey! newbie here :h: hmm…i´m trying to start to learn actionscript. so, my idea is to just draw an animated square within i will load an image. but first off i´m trying to draw a straight line from one point to another. my probs is that i would like to control the speed the line will be drawn, first i want it to draw the x-axis quite fast, make a pause and then draw the y-axis and paus. i´m trying to use setInterval(function, speed), but it doesn´t quite work thou :upset: here´s my code:

\_root.createEmptyMovieClip(“mc\_clip”, 0);

function drawLine() {  
//variablar  
x = 0;  
y = 20;

```
mc_clip.onEnterFrame = function() {
	mc_clip.createEmptyMovieClip("newLine", 1);
	with(newLine) {
		lineStyle(1, 0x000000, 100);
		moveTo(200, 20);
		lineTo(x++, y);
	};
};

```

};  
this.drawLine();  
setInterval(drawLine, 1000);

---

<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:** [September 22, 2004, 9:15pm UTC](https://forum.kirupa.com/t/newbie-about-animating-a-line-in-actionscript/65078/2 "2004-09-22T21:15:27Z")

</div>

sorry, thanks for answers :s:

---

<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:** [September 22, 2004, 9:37pm UTC](https://forum.kirupa.com/t/newbie-about-animating-a-line-in-actionscript/65078/3 "2004-09-22T21:37:51Z")

</div>

> [@hendersson](#):
>
> hey! newbie here :h: hmm…i´m trying to start to learn actionscript. so, my idea is to just draw an animated square within i will load an image. but first off i´m trying to draw a straight line from one point to another. my probs is that i would like to control the speed the line will be drawn, first i want it to draw the x-axis quite fast, make a pause and then draw the y-axis and paus. i´m trying to use setInterval(function, speed), but it doesn´t quite work thou :upset: here´s my code:
> 
> \_root.createEmptyMovieClip(“mc\_clip”, 0);
> 
> function drawLine() {  
> //variablar  
> x = 0;  
> y = 20;
> 
> ```
> mc_clip.onEnterFrame = function() {
> mc_clip.createEmptyMovieClip("newLine", 1);
> with(newLine) {
> lineStyle(1, 0x000000, 100);
> moveTo(200, 20);
> lineTo(x++, y);
> };
> };
> 
> ```
> 
> };  
> this.drawLine();  
> setInterval(drawLine, 1000);

Not exactly what you want but may get you going in the right direction

myArray = [[100, 200], [200, 200], [200, 100], [100, 100], [100, 200]];  
this.createEmptyMovieClip(“paper”, 1);  
paper.lineStyle(1, 0x000000, 100);  
i = 0;  
paper.moveTo(myArray\*[0], myArray\*[1]);  
function draw() {  
j = i+1;  
if (j\<myArray.length) {  
incX1 = (myArray[j][0]-myArray\*[0])/10;  
incY1 = (myArray[j][1]-myArray\*[1])/100;  
} else {  
incX1 = 0;  
incY1 = 0;  
}  
incX += incX1;  
incY += incY1;  
paper.lineTo(myArray\*[0]+incX, myArray\*[1]+incY);  
if (i\<myArray.length-1) {  
if (myArray\*[0]+incX == myArray[j][0] && myArray\*[1]+incY == myArray[j][1]) {  
trace(“done”);  
clearInterval(myInterval);  
i += 1;  
incX = 0;  
incY = 0;  
myInterval = setInterval(draw, 20);  
}  
} else {  
clearInterval(myInterval);  
}  
}  
myInterval = setInterval(draw, 20);
