# How to the line effect with actionscript!

**URL:** https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071
**Category:** flash
**Created:** [December 23, 2002, 8:17pm UTC](https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071 "2002-12-23T20:17:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cookie](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cookie](https://forum.kirupa.com/u/cookie)
#### Post date: [December 23, 2002, 8:17pm UTC](https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071/1 "2002-12-23T20:17:21Z")

</div>

[http://www.8ballcreations.com/lostinbeta/cfr\_main.html](http://www.8ballcreations.com/lostinbeta/cfr_main.html)

In the above movie there are lines moving back and forth, but they are individual layers. Is it possible to make a random movement with only one line being copied with actionscript?

---

<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: [December 23, 2002, 8:31pm UTC](https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071/2 "2002-12-23T20:31:04Z")

</div>

Yes you can… I will be using modified code from the Random Motion in Flash MX tutorial on this site…  
[http://www.kirupa.com/developer/mx/random\_motionMX.asp](http://www.kirupa.com/developer/mx/random_motionMX.asp)

Ok, first, create a line on the stage and convert it to a movie clip symbol. Next give it the instance name “line”.

Right click on it and open the actions panel.

Apply these actions to the movie clip…

```auto
onClipEvent (enterFrame) {
	move();
}

```

Now, Right click on the keyframe and open the actions panel. And apply these actions to the Frame…

```auto
//special thanks to Suprabeener for the code
//specify the width of the movie
width = 300;
function getdistance(x, x1) {
	var run, rise;
	run = x1-x;
	return (_root.hyp(run));
}
function hyp(a, b) {
	return (Math.sqrt(a*a+b*b));
}
MovieClip.prototype.reset = function() {
	//-------------------
	var dist, norm;
	this.x = this._x;
	this.speed = Math.random()*4+2;
	this.targx = Math.random()*width;
	dist = _root.getdistance(this.x, this.targx);
	norm = this.speed/dist;
	this.diffx = (this.targx-this.x)*norm;
};
MovieClip.prototype.move = function() {
	if (_root.getdistance(this.x, this.targx)>this.speed) {
		this.x += this.diffx;
	} else {
		this.x = this.targx;
		if (!this.t) {
			this.t = getTimer();
		}
		if (getTimer()-this.t>1000) {
			this.reset();
			this.t = 0;
		}
	}
	this._x = this.x;
};
for (i=0; i<5; i++) {
	_root.line.duplicateMovieClip("line"+i, i);
	myLine = _root["line"+i];
	myLine._x = Math.random()*width;
}

```

PS: Refresh my memory… was it you who I fixed that file for in the first place? I can’t remember who I fixed it for, or what I fixed…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: [December 23, 2002, 8:38pm UTC](https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071/3 "2002-12-23T20:38:34Z")

</div>

Thanks lostinbeta!

---

<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: [December 23, 2002, 8:50pm UTC](https://forum.kirupa.com/t/how-to-the-line-effect-with-actionscript/10071/4 "2002-12-23T20:50:20Z")

</div>

No problem 🙂
