Random Motion!

I’m trying to make add this little movie clip to my page but I can’t seem to get it to work properly. What I’m trying to do is this. I have a bunch of short lines and i want them to move up and down smoothly and continously. I looked at the random motion tut on the site but it didn’t look like what I was after.

Can some one help?


PS. you can view the site at www.jcgsolutions.ca so you can have a look at what I’m talking about. The movie clip is in the upper right corner.


Just remove EVERYTHING that relates to the _x position of the object. Here… I edited the script for what you want to do, Tried, tested, and true it works…

//special thanks to Suprabeener for the code
function getdistance(y, y1) {
	var rise;
	rise = y1-y;
	return (_root.hyp(rise));
function hyp(a, b) {
	return (Math.sqrt(a*a+b*b));
MovieClip.prototype.reset = function() {
	//specify the width and height of the movie
	width = 300;
	height = 400;
	var dist, norm;
	this.y = this._y;
	this.speed = Math.random()*4+2;
	this.targy = Math.random()*height;
	dist = _root.getdistance(this.y, this.targy);
	norm = this.speed/dist;
	this.diffy = (this.targy-this.y)*norm;
MovieClip.prototype.move = function() {
	if (_root.getdistance(this.y, this.targy)>this.speed) {
		this.y += this.diffy;
	} else {
		this.y = this.targy;
		if (!this.t) {
			this.t = getTimer();
		if (getTimer()-this.t>1000) {
			this.t = 0;
	this._y = this.y;

Just replace the frame actions with the actions above and it should work the way you wanted.

To change the speed just change this line…
this.speed = Math.random()*4+2;


I can’t seem to get it to work though. Maybe I’m not adding the code to right spot. Do I put in the main timeline or in the movie clip itself?

Thanks again…I’ll keep trying.


That code goes on the main timeline. On a Frame.

The code given to you for the movie clip is in the tutorial, I believe it is something like this…


So the first code I gave you goes on the timeline in a Frame and the code above goes directly on your movie clip.

Thanks alot!! it’s working fine now! I should’ve known to do that.


It is good that you got it working:)