# Dynamicly generated movieclips and their eventlisteners

**URL:** <https://forum.kirupa.com/t/dynamicly-generated-movieclips-and-their-eventlisteners/248127>\
**Category:** Uncategorized\
**Created:** [January 4, 2008, 4:28am UTC](https://forum.kirupa.com/t/dynamicly-generated-movieclips-and-their-eventlisteners/248127 "2008-01-04T04:28:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmilesp](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bmilesp](https://forum.kirupa.com/u/bmilesp)\
**Post date:** [January 4, 2008, 4:28am UTC](https://forum.kirupa.com/t/dynamicly-generated-movieclips-and-their-eventlisteners/248127/1 "2008-01-04T04:28:41Z")

</div>

I have a movieclip called polaroid from the library. The code below works as expected- (minus a few other irrelevent lines). The code produces a 2x5 grid of polaroid objects (basically squares). The problem is in the event listener. When i click on one of the polaroids, i want the dropandsplash effect to affect only the instance of the polaroid object i’ve clicked. It seems to me that there is no way to reference the obj[count] that the event is attached to (eg: using “this” reference) in dropandsplash. the result is the entire stage doing the dropandsplash rather that the “clicked” instance of polaroid. I know i can use obj[0], obj[1], etc, but i need to reference the polaroid instance directly. Is it possible to reference itself within the scope of the dropandsplash evenlistener callback? I know it was possible to achieve this in AS2 using attachMovie. Thanks in advance. -bmiles

count=0;  
totalRows=2;  
totalColumns-5;  
for( var i:int = 0; i\<totalRows; i++){  
for( var j:int=0; j\<totalColumns; j++){  
obj[count] = new polaroid();  
this.addChild(obj[count]);  
obj[count].x=j_130;  
obj[count].y=i_130;  
obj[count].addEventListener(MouseEvent.CLICK, dropAndSplash);  
trace(obj[count].x);  
count++;  
}  
}

function dropAndSplash(evt:Event):void{  
var myTween1:Tween = new Tween(this, “rotation”, None.easeOut, 1, 20, 4, true);  
var myTween2:Tween = new Tween(this, “scaleX”, None.easeOut, 1,0.7, 0.2, true);  
var myTween3:Tween = new Tween(this, “scaleY”, None.easeOut, 1, 0.7, 0.2, true);  
}
