# \[HELP\]AS3 for loop naming

**URL:** <https://forum.kirupa.com/t/help-as3-for-loop-naming/317674>\
**Category:** flash\
**Created:** [December 29, 2010, 7:05pm UTC](https://forum.kirupa.com/t/help-as3-for-loop-naming/317674 "2010-12-29T19:05:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiong1990](https://avatars.discourse-cdn.com/v4/letter/x/71c47a/32.png) [@xiong1990](https://forum.kirupa.com/u/xiong1990)\
**Post date:** [December 29, 2010, 7:05pm UTC](https://forum.kirupa.com/t/help-as3-for-loop-naming/317674/1 "2010-12-29T19:05:21Z")

</div>

Hi every body, I’m quite new in action script 3. I have a problem with for loop naming in AS3.

So what i want is action script is looping and add several movie clip to the stage (same movieclip). Then each movieClip added an event listener with several different function.

here is the sample script i can do right now.(which’s not working)

var myX:Number = -200  
for(var i:Number=0 ; i\<5 ; i++){  
var myMc\_mc:MovieClip = new mc;  
myX +=200  
myMc\_mc.x= myX  
myMc\_mc.name= “mc”+i;  
addChild(myMc\_mc)  
}

myMc\_mc.mc1.addEventListener(MouseEvent.CLICK,myFunction)  
myMc\_mc.mc2.addEventListener(MouseEvent.CLICK,myFunction2)

function myFunction(e:MouseEvent):void{  
trace(“clicked”)  
}

function myFunction2(e:MouseEvent):void{  
trace(“clicked2”)  
}
