Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-24-2004, 02:55 AM   #1
Fishinghat
Registered User
 
Join Date: Aug 2004
Posts: 23
Default 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!
Fishinghat is offline   Reply With Quote
Old 08-24-2004, 05:10 AM   #2
Billy T
Oops I did it again
 
Billy T's Avatar
 
Join Date: Oct 2001
Location: Melbourne
Posts: 8,579
Default

maybe

_root["addCloud"+numClickClouds].onEnterFrame=function(){

this.move();
}
__________________
Billy
Online Galleries
iPhone Safety App - iStaySafe
Free Flash Video Tutorials
Photo Website Template

Don't email or PM me questions...
Billy T is offline   Reply With Quote
Old 08-24-2004, 05:18 AM   #3
Fishinghat
Registered User
 
Join Date: Aug 2004
Posts: 23
Default thanks

thanks, now it moves, but it moves the whole stage, what line of code do i have to add to it?
Fishinghat is offline   Reply With Quote
Old 08-24-2004, 06:08 AM   #4
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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
farafiro is offline   Reply With Quote
Old 08-24-2004, 06:24 AM   #5
Fishinghat
Registered User
 
Join Date: Aug 2004
Posts: 23
Default

how do i put the function into onEnterFrame
just
onEnterFrame {
//code in here
}

? not really sure how to put it in
Fishinghat is offline   Reply With Quote
Old 08-24-2004, 06:42 AM   #6
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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
farafiro is offline   Reply With Quote
Old 08-24-2004, 06:47 AM   #7
Fishinghat
Registered User
 
Join Date: Aug 2004
Posts: 23
Default

sorry to bug you again, but it moves the whole stage instead of the individual movie clip
Fishinghat is offline   Reply With Quote
Old 08-24-2004, 07:01 AM   #8
farafiro
Addicted To FLASH
 
farafiro's Avatar
 
Join Date: Dec 2001
Location: Egyptian in UAE
Posts: 12,436
Send a message via MSN to farafiro Send a message via Yahoo to farafiro
Default

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
farafiro is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:44 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.