# Problem assigning dynamic event handlers to dynamically created clips

**URL:** https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517
**Category:** flash
**Created:** [April 5, 2006, 5:21pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517 "2006-04-05T17:21:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Lukeomalley](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@Lukeomalley](https://forum.kirupa.com/u/Lukeomalley)
#### Post date: [April 5, 2006, 5:21pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/1 "2006-04-05T17:21:48Z")

</div>

I am in a for loop creating clips and assigning a rollover script to each. It works if I hard code gallery\_mc1.enterFrame = navGrow; I have pasted the relevant parts of the script below.

```
this["gallery_mc"+i].onRollOver = function() {
    this["gallery_mc"+i].enterFrame = navGrow();
};

```

//////////////////////////////////////  
navGrow = function () {  
if (this.\_xscale\<100) {  
trace(“it triggered navGrow”);  
this.\_yscale = this.\_xscale += 5;  
this.\_y -= 5;  
this.\_x -= 5;  
} else {  
this.onEnterFrame = null;  
}  
};

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 5, 2006, 5:25pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/2 "2006-04-05T17:25:50Z")

</div>

That code looks fine, post the rest of the loop. I usually use a variable to refer to the movieclip for events like this.

Edit: wait… what is enterFrame, shouldn’t that be “onEnterFrame”?

---

<div class="post-metadata">

### Author: ![Lukeomalley](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@Lukeomalley](https://forum.kirupa.com/u/Lukeomalley)
#### Post date: [April 5, 2006, 5:28pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/3 "2006-04-05T17:28:42Z")

</div>

Here is the rest. When you talk about assigning a variable you mean something like this?  
temp\_mc = this[“gallery\_mc”+i];

///////////////////////

import flash.display.BitmapData;  
import mx.transitions.Tween;  
import mx.transitions.easing.\*;  
var offset = 0;  
for (i=1; i\<5; i++) {  
// Create imageBmp and attach the bitmap from the library.  
//var imageBmp:BitmapData = BitmapData.loadBitmap(“image”+i);  
// create movie clip and attach imageBmp  
this.createEmptyMovieClip(“gallery\_mc”+i, i);  
this[“gallery\_mc”+i].loadMovie(“images/gallery”+i+".swf");  
this[“gallery\_mc”+i].\_xscale = this[“gallery\_mc”+i].\_yscale=70;  
this[“gallery\_mc”+i].\_y = 100;  
this[“gallery\_mc”+i].\_x = offset += 3;  
offset += 170;//this[“gallery\_mc”+i].\_width;  
trace("offset = " +offset);  
trace("gallery\_mci = "+this[“gallery\_mc”+i]);  
trace("gallery\_mci.\_width = "+this[“gallery\_mc”+i].\_width);  
//////////////////////////////////  
this[“gallery\_mc”+i].onRollOver = function() {  
this[“gallery\_mc”+i].enterFrame = navGrow();  
};  
//////////////////////////////////  
this[“gallery\_mc”+i].onRollOut = function() {  
this[“gallery\_mc”+i].enterFrame = navShrink();  
};  
}  
this.stop();  
///////////////////////////////////////////////  
navGrow = function () {  
if (this.\_xscale\<100) {  
trace(“it triggered navGrow”);  
this.\_yscale = this.\_xscale += 5;  
this.\_y -= 5;  
this.\_x -= 5;  
} else {  
this.onEnterFrame = null;  
}  
};  
////////////////////////////////////  
navShrink = function () {  
if (this.\_yscale\>70) {  
this.\_xscale = this.\_yscale -= 5;  
this.\_y += 5;  
this.\_x += 5;  
} else {  
this.onEnterFrame = null;  
}  
};  
//////////////

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 5, 2006, 5:39pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/4 "2006-04-05T17:39:57Z")

</div>

No, more like this:

```auto
import flash.display.BitmapData;
import mx.transitions.Tween;
import mx.transitions.easing.*;
var offset = 0;
for (i=1; i<5; i++) {
   // Create imageBmp and attach the bitmap from the library.
   //var imageBmp:BitmapData = BitmapData.loadBitmap("image"+i);
   // create movie clip and attach imageBmp
   var gallmc:MovieClip = this.createEmptyMovieClip("gallery_mc"+i, i);
   gallmc.loadMovie("images/gallery"+i+".swf");
   gallmc._xscale = gallmc._yscale=70;
   gallmc._y = 100;
   gallmc._x = offset += 3;
   offset += 170;//this._width;
   trace("offset = " +offset);
   trace("gallery_mci = "+this);
   trace("gallery_mci._width = "+this._width);
   //////////////////////////////////
   gallmc.onRollOver = function() {
      this.onEnterFrame = navGrow();
   };
   //////////////////////////////////
   gallmc.onRollOut = function() {
      this.onEnterFrame = navShrink();
   };
}
this.stop();
///////////////////////////////////////////////
navGrow = function () {
   if (this._xscale<100) {
      trace("it triggered navGrow");
      this._yscale = this._xscale += 5;
      this._y -= 5;
      this._x -= 5;
   } else {
      this.onEnterFrame = null;
   }
};
////////////////////////////////////
navShrink = function () {
   if (this._yscale>70) {
      this._xscale = this._yscale -= 5;
      this._y += 5;
      this._x += 5;
   } else {
     this.onEnterFrame = null;
   }
};
//////////////

```

---

<div class="post-metadata">

### Author: ![Lukeomalley](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@Lukeomalley](https://forum.kirupa.com/u/Lukeomalley)
#### Post date: [April 5, 2006, 5:42pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/5 "2006-04-05T17:42:52Z")

</div>

I switched the whole thing so that it is using a temp variable and it still doesn’t work.  
this.createEmptyMovieClip(“gallery\_mc”+i, i);  
temp\_mc = this[“gallery\_mc”+i];

---

<div class="post-metadata">

### Author: ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)
#### Post date: [April 5, 2006, 5:48pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/6 "2006-04-05T17:48:31Z")

</div>

Umm… did you read my post?

---

<div class="post-metadata">

### Author: ![Lukeomalley](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@Lukeomalley](https://forum.kirupa.com/u/Lukeomalley)
#### Post date: [April 5, 2006, 6:57pm UTC](https://forum.kirupa.com/t/problem-assigning-dynamic-event-handlers-to-dynamically-created-clips/184517/7 "2006-04-05T18:57:45Z")

</div>

I tried your method, but I can’t get it to work. I don’t know what to do… I am going to try messing around with a blank clip and duplicateMovieClip. That isn’t working either. UGH!!!
