# How do I apply same code to many movie clips

**URL:** <https://forum.kirupa.com/t/how-do-i-apply-same-code-to-many-movie-clips/52915>\
**Category:** flash\
**Created:** [May 28, 2004, 7:20pm UTC](https://forum.kirupa.com/t/how-do-i-apply-same-code-to-many-movie-clips/52915 "2004-05-28T19:20:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![smd\_ksu](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@smd\_ksu](https://forum.kirupa.com/u/smd_ksu)\
**Post date:** [May 28, 2004, 7:20pm UTC](https://forum.kirupa.com/t/how-do-i-apply-same-code-to-many-movie-clips/52915/1 "2004-05-28T19:20:35Z")

</div>

I have alot of mc’s and I want them all to have the same code applied to them without having to copy/paste all the code in each one and also it would be easier for any changes latter. I have tried making the code a function and then calling it inside the mc’s but it did not work and I am fairly new at functions themselves so I am stuck.

This is the code below-

onClipEvent (load) {  
targetx = this.\_x;  
targety = this.\_y;  
this.\_y = 0;  
this.\_x = 0;  
speed = 4;  
size = random(100);  
this.\_xscale = size+100;  
this.\_yscale = size+100;  
onEnterFrame = function () {  
this.\_x += (targetx-this.\_x)/speed;  
this.\_y += (targety-this.\_y)/speed;  
this.\_alpha += (0-this.\_alpha)/7;  
if (this.\_alpha\<=0) {  
this.removeMovieClip();  
}  
};  
}

The code marks the mc position, then moves it to 0,0 then moves back to the original postion while degrading alpha. I set it up this way so I can arrange the mc in any shape and the mc’s will look like they explode into the shape when played. It is used for a fireworks effect.

Thanks
