Greetings!
Having followed the tut on the random moving mc I have 1 question. I would like the mc to move inside a box I have on my stage. Do I need to do this as a seperate swf file and load it into my main movie? Adjusting the width and height in the code given does nothing. My mc keeps sailing out of the box and hanging around the left side of the screen. If I am correct the coded paramaters for the moviing mc is in reference to the size of the total movie (my main movie is like 700x500, my box is 570 by 400). I wanna keep the kids in my sandbox.
Any ideas?
Thanks!
P.S. I seem to be unable to import the above movie into another’s library. I exported the movie as a swf (of course) and then tried to import it into library of my main movie. All I was able to get were the symbols, but not the swf. Any ideas why that would be?
Thanks again.
Much thanks for the help!
So where in the code would I add your additional script?
Do I take out the width= and the height= and replace with what you gave me?
Here is the script I have:
function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(aa+bb));
}
MovieClip.prototype.reset = function() {
// specify the width and height of the movie
width = 500;
height = 350;
// -------------------
var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+2;
this.targx = Math.random()*width;
this.targy = Math.random()*height;
dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;
};
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
};
in the last line of the code
replace instance with the instance name of your movie clip
and place there the minimum x and y values and the maximum x and y values
Now, one of my movie clips to be moved about is called “mycircle1” as you see above. I also have instances of “mycircle2” and “mycircle3” on my stage. All have an:
onClipEvent (enterFrame) {
move();
}
action on them.
So mycircle1 is not moving at this point and I am not sure how I am going to animate each seperate clip.
I suppose everybody is getting tired of this enquire. Thanks for the patience. I still need to work this out.
Thanks.
Well it’s working.
Thanks for the help.
Alas the motion is too fast and I can’t seem to get each mc (all seperate mcs not instances of the same one) circle to float around independently (they seem to group together and move together).
Anyhow, I’ll tool around with it.
The original script worked well but for some reason I can’t publish it in a form that will import into another movie’s library, and the width= and height= never seem to adjust anything.
Ok well I wasn’t able to import the swf into my library but I was able to loadmovie the swf and load into target.
Oddly enough the circles now jump as oppose to move!
I tried adjusting the frame rate(redid fla and re-exported so that swf is 18fps and so is my main) but that didn’t do anything. Somethin is amiss here. I am working with the original script (seen above as suprabeener’s script) cause the speed was better and I was able to have each mc move independently as oppose to immediatly grouping together and moving together which was the problems I had with the shorter script posted above.
Adjusting width and height in the suprabeener script works but will send all the circles to the upper left of my movie i.e. my main movie doc is 550 x 400 my random moving circles are set width=300 height=100 and so that 300x100 area becomes the upper left of 550 x 400. This is no good cause I need to place the 300x100 random movement a specific codinates inside the main movie. Hence my desire to just loadmovie into target mc the random movement swf.
I think I need to find suprabeener to help with this problem.
Where he at?
Can’t figure out why as a fla all moves smooth but as a exported swf it’s all jumpy.
Thanks!
Eli:trout:
:flower:
Well, with the inclusion of your code I was able to get everything moving. In addition I was able to exort and import into my main movie just fine. Gracias!
With your script my circles move in a stop and go fashion. Is there a way to have a more continuos movement?
Also how does the paramaters for the mc A.S. (200, 200, 400, 400) work with the main timeline A.S. which also has miny, minx, and maxy, maxx, parameters as well? I mean as I match up your 1st initial code with the secondary code you gave. Does one overide the other or do they work together?
Also I discovered that it is possible to have the random moving circles as buttons but is there a way to stop a circle’s movement upon mouse over? I may be getting into too deep of waters with that one but I thought I’d ask anyways.
Thanks!
:cowboy:
Out of curiosity anyone know why Suprabreener’s script for random mc does not export properly?
Meaning I export the random mc and import into my main movie into a target mc aaaandd the fluidity of the movement is lost. All I get is a extremely choppy version like I am missing frames or something.
Thanks.
:whistle:
Creating engaging and entertaining content for designers and developers since 1998.