# getInstanceByname

**URL:** <https://forum.kirupa.com/t/getinstancebyname/318182>\
**Category:** flash\
**Created:** [January 12, 2011, 12:23pm UTC](https://forum.kirupa.com/t/getinstancebyname/318182 "2011-01-12T12:23:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daragh\_c](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@daragh\_c](https://forum.kirupa.com/u/daragh_c)\
**Post date:** [January 12, 2011, 12:23pm UTC](https://forum.kirupa.com/t/getinstancebyname/318182/1 "2011-01-12T12:23:26Z")

</div>

Hi Guys.

Im trying to make instance names for movie clips via a loop. Basically, every new instance of the movie clip should have an addEventlistener (mouseclick,someFunction)  
What I have is ;

for (var i:Number=0; i\<len; i++) {  
var c:teamLineUp\_mc = new teamLineUp\_mc();  
**c.name = “players”+i;  
var instanceVariable = getInstanceByName(“players”+i);  
instanceVariable.addEventListener(MouseEvent.CLICK,displayDetails);**  
**}**

I can add the clips to the stage and everything; it’s just that I need to add a unique name for each instance, as there are text fileds within the movie clips that are populated by xml data.

When I click on the movie clip I will need to access the information. But for now I just need to give the movie clips new names after each loop.

Im getting error : 1180: Call to a possibly undefined method getInstanceByName.

Im not sure what the import line is (Using external as3). Currently I have ;

import flash.utils.getDefinitionByName;  
import flash.utils.getQualifiedClassName;

Any ideas ?  
Cheers  
D
