# Add on(press) event to dynamically created movieclips

**URL:** <https://forum.kirupa.com/t/add-on-press-event-to-dynamically-created-movieclips/294093>\
**Category:** Uncategorized\
**Created:** [August 8, 2009, 6:05am UTC](https://forum.kirupa.com/t/add-on-press-event-to-dynamically-created-movieclips/294093 "2009-08-08T06:05:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![patspats](https://avatars.discourse-cdn.com/v4/letter/p/b782af/32.png) [@patspats](https://forum.kirupa.com/u/patspats)\
**Post date:** [August 8, 2009, 6:05am UTC](https://forum.kirupa.com/t/add-on-press-event-to-dynamically-created-movieclips/294093/1 "2009-08-08T06:05:46Z")

</div>

hi everyone

i have a movieclip named “mc” and i want to load many images in it and add on press event to those images.

For that, i have a button which is when click adds images to movieclip “mc”.

I created empty movie clip in “mc” and loaded that empty movie clip with images. But i m not able to attach on press event to that empty movie clip.

Here is my code:-

In button :-

on(press)  
{   
\_root.fun();  
}

In actions frame :-

\_root.i = 1;

/\*  
var styleListener:Object = new Object();  
styleListener.click = function(eventObj:Object) {   
trace(“style click”);  
};  
\*/

function fun()  
{   
if(\_root.i \< 9)  
{  
trace("buton clicked = " + \_root.i);  
for(var ii:Number = 1; ii \< \_root.i; ii++)  
{  
trace(\_root.mc[“a” + ii]);  
}

```
	_root.mc.createEmptyMovieClip("a"+_root.i, _root.mc.getNextHighestDepth());
	loadMovie("Images/"+_root.i+".png",_root.mc["a"+_root.i]);
	_root.mc["a"+_root.i]._x = 30*_root.i;
	_root.mc["a"+_root.i]._y = 30*_root.i;
	
	//_root.mc["a"+_root.i].addEventListener("click", styleListener);	
	_root.mc["a"+_root.i].onPress = function()
	{
		trace("on press");
	};

	_root.i++;	
}

```

}

I even tried to add listener to movie clip (commented portion in above code) but that also didnt work.

Please can somebody tell me where am i doing mistake.

Please…

I m attaching my file if anybody wants more information.

Thank you for helping.
