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?
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?
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
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…
onClipEvent (enterFrame) {
move();
}
Now, Right click on the keyframe and open the actions panel. And apply these actions to the Frame…
//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.
Thanks lostinbeta!
No problem
:: Copyright KIRUPA 2024 //--