Groups | Blog | Home
all groups > flash actionscript > february 2004 >

flash actionscript : reusing code on movie clip event



asiabackpacker
2/17/2004 9:48:53 PM
i know this is a pretty basic question, but I am having trouble finding an
answer, so please bear with me:

I have a script that is attached to several different movie clips, and is
triggered when the user clicks on the clip. Instead of copying the same piece
of code to every instance of the clip, how do I trigger a piece of code that
resides somewhere else

thank
Vimpact
2/17/2004 10:14:50 PM
On each of you movie clip you want to control name their instance names in
order (myMovie1,myMovie2,myMovie3,etc.

Then try using a function... in frame 1 on your timeline setup a functions
layer and on the first frame add something like this...

// creates a new functio
function MyFunctionName(){
// creates a for loop for 10 movie clips, but you can change the 20 to the
number of clips you will use this code on
for(i=1;i<=10;i++)
//will set all the movie clips 1-10's X position down 1
_root["myMovie"+i]._y=_root["myMovie"+i]._y+10




You will still need a way to trigger the function. So whatever button you are
pressing to trigger this code you will need the following script

// calls the function MyFunctionNam
_root.MyFunctionName()

I'm still kinda new at this actionscript thing too. So someone else might have
a better suggestion. But this is how I've beeing doing similar things

Hope this helps

Brya
asiabackpacker
2/17/2004 11:00:23 PM
Vimpact
2/18/2004 4:42:07 AM
No problem! Just glad I could help.

Good luck!

AddThis Social Bookmark Button