08-24-2004, 02:55 AM
|
#1
|
|
Registered User
Join Date: Aug 2004
Posts: 23
|
Movement in Duplicating a movie Clip
Hi
I just created a script for my frame and another for script that duplicates movie clips when you click on the button, how do i get the movie clips that are duplicated to move? Here's my frame script:
/* This script has three main functions:
1. Gets the distance of the Movie Clip
2. Resets the stage to allow constrictions for Movie
clips to not exit the stage area
3. Has a move function to move the movie clip randomly
*/
/* Function gets the distance of x,y and returns it with
hypotenuse function affecting the x,y values */
function getDistance(x, y, x1, x2){
var run, rise;
run = x1 -x;
rise = y1-y;
return(hyp(run, rise));
}
function hyp(a,b){
return(Math.sqrt(a*a+b*b));
}
/* Resets the stage by setting constrains for moving
the movie clips */
MovieClip.prototype.reset = function() {
/* movieHeight and movieWidth refers to the height
and width of the stage */
var dist, norm, movieHeight, movieWidth;
movieHeight = Stage.height;
movieWidth = Stage.width;
// sets minimum speed of movement of movie clip
speed = Math.random()*4+2;
/* Sets the x, y position in which the movie clip
is to go to */
targx = Math.random()*(movieWidth-_width);
targy = Math.random()*(movieHeight-_height);
// Calls Upon the function getDistance
dist = _root.getDistance(_x, _y, targx, targy);
// Sets the value of norm
norm = speed/dist;
// Sets the speed of movie clip
diffx = (targx-_x)*norm;
diffy = (targy-_y)*norm;
};
// Function move moves the actual movie clip
MovieClip.prototype.move = function(){
if(_root.getDistance(_x, _y, targx, targy)>speed){
x += diffx;
y += diffy;
}
else {
x = targx;
y = targy;
if(!this.t){
t = getTimer();
}
if(getTimer()-t>cycle){reset();
t = 0;
}
}
_x = x;
_y = y;
}
var numClickClouds = 0;
var speedCloud = (Math.random()*50)+5;
And my button script that duplicates movie clip:
on (press, release) {
var createClouds = 0;
while (createClouds<8) {
numClickClouds++;
createClouds++;
duplicateMovieClip(_root.theCloud, "addCloud"+numClickClouds, numClickClouds);
_root["addCloud"+numClickClouds]._alpha = (Math.random()*100) +10;
_root["addCloud"+numClickClouds]._y = Math.random()*550;
_root["addCloud"+numClickClouds]._x = Math.random()*600;
_root["addCloud"+numClickClouds].move();
}
}
At the moment when i click, they don't move at all, but do come out with the duplication.
Thanks in advance!
|
|
|
08-24-2004, 05:10 AM
|
#2
|
|
Oops I did it again
Join Date: Oct 2001
Location: Melbourne
Posts: 8,579
|
maybe
_root["addCloud"+numClickClouds].onEnterFrame=function(){
this.move();
}
|
|
|
08-24-2004, 05:18 AM
|
#3
|
|
Registered User
Join Date: Aug 2004
Posts: 23
|
thanks
thanks, now it moves, but it moves the whole stage, what line of code do i have to add to it?
|
|
|
08-24-2004, 06:08 AM
|
#4
|
|
Addicted To FLASH
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
|
some comments:
1). within the functions u should refer to the object you want it to grab or get its propert, like these for example
ActionScript Code:
targx = Math.random()*(movieWidth-_width);// shouol be this._width or _root._width
targy = Math.random()*(movieHeight-_height);// the same
//also
dist = _root.getDistance(_x, _y, targx, targy);// the _x and _y for what??
2). and also, u get the dist value in the reste prototype, and in the move too where you can use it not re-calculating it again
3). within the move prototype, this should go withing onEnterFrame
ActionScript Code:
if(_root.getDistance(_x, _y, targx, targy)>speed){
x += diffx;
y += diffy;
}
else {
x = targx;
y = targy;
if(!this.t){
t = getTimer();
}
if(getTimer()-t>cycle){reset();
t = 0;
}
}
_x = x;
_y = y;
}
4). good luck
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
|
|
|
08-24-2004, 06:24 AM
|
#5
|
|
Registered User
Join Date: Aug 2004
Posts: 23
|
how do i put the function into onEnterFrame
just
onEnterFrame {
//code in here
}
? not really sure how to put it in
|
|
|
08-24-2004, 06:42 AM
|
#6
|
|
Addicted To FLASH
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
|
ActionScript Code:
MovieClip.prototype.move = function(){
this.onEnterFrame = function(){
if(_root.getDistance(_x, _y, targx, targy)>speed){
x += diffx;
y += diffy;
}
else {
x = targx;
y = targy;
if(!this.t){
t = getTimer();
}
if(getTimer()-t>cycle){reset();
t = 0;
}
}
_x = x;
_y = y;
}
}
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
|
|
|
08-24-2004, 06:47 AM
|
#7
|
|
Registered User
Join Date: Aug 2004
Posts: 23
|
sorry to bug you again, but it moves the whole stage instead of the individual movie clip
|
|
|
08-24-2004, 07:01 AM
|
#8
|
|
Addicted To FLASH
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
|
when u call the getDistance u should spacify these:
_x, _y, targx, targy, as I mentioned the _x and _y for what
if it still didn't work, try to post a sample fla
__________________
â€* GOD Is Near â€*
Questions Don't PM for Questions . Thanks
An eye for an eye, make the whole world blind
_____________________________________________GHANDI
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 04:44 PM.
///
|
|