# Defining a function for a dynamically created clip?

**URL:** <https://forum.kirupa.com/t/defining-a-function-for-a-dynamically-created-clip/223059>\
**Category:** Uncategorized\
**Created:** [April 19, 2007, 5:44am UTC](https://forum.kirupa.com/t/defining-a-function-for-a-dynamically-created-clip/223059 "2007-04-19T05:44:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceblueflame](https://avatars.discourse-cdn.com/v4/letter/i/bbe5ce/32.png) [@iceblueflame](https://forum.kirupa.com/u/iceblueflame)\
**Post date:** [April 19, 2007, 5:44am UTC](https://forum.kirupa.com/t/defining-a-function-for-a-dynamically-created-clip/223059/1 "2007-04-19T05:44:12Z")

</div>

i wanna write a function for the onPress handler for a movieclip that will be created dynamically… how do i do it? this is what i’m doing:

only the ending part of this loop is relevant, where i am writing the thisMC.onpress function. The trace text never appears…

```auto

 
for (var i = 0; i<galleryLength; i++) 
  {
    var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
    loadMovie(gallery_array*.src, thisMC);
 
   thisMC._x = 50*xPos+adjust;
   xPos++;
   thisMC._y = 50*yPos;
   thisMC._xscale = 10;
   thisMC._yscale = 10;
   trace(thisMC+" "+thisMC._x+" "+thisMC._y);
      if ((i+1)%5 == 0)
   {
      yPos++;
    xPos = 0;
   }
   //Here lies the problem:
   thisMC.onPress = function()
   {
    trace("Pressed "+this);
   }
}
 

```

this whole loop is inside the onClipEvent(load) of another clip. So when that clip is loaded, this code is executed…
