# Trouble with .onPress within a loop (array of movieclips)

**URL:** https://forum.kirupa.com/t/trouble-with-onpress-within-a-loop-array-of-movieclips/327525
**Category:** flash
**Created:** [March 7, 2012, 3:06am UTC](https://forum.kirupa.com/t/trouble-with-onpress-within-a-loop-array-of-movieclips/327525 "2012-03-07T03:06:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![kremfjes](https://avatars.discourse-cdn.com/v4/letter/k/45deac/32.png) [@kremfjes](https://forum.kirupa.com/u/kremfjes)
#### Post date: [March 7, 2012, 3:06am UTC](https://forum.kirupa.com/t/trouble-with-onpress-within-a-loop-array-of-movieclips/327525/1 "2012-03-07T03:06:34Z")

</div>

Hi!  
I’m not a very good programmer, but i’m trying to make a point and click game for the fun of it. Now I’m very stuck, and i need some help.

I’m having troubble with the .onPress function. I’ve made an array of movieclips, and i want to go through them in a loop, and make an onPress function for each of them. What im trying to do with the code below is to make the debugText tell me what movieclip i pressed:

var letterArray = new Array();  
letterArray = [l1\_mc, l2\_mc, l3\_mc, l4\_mc, l5\_mc, l6\_mc, l7\_mc, l8\_mc, l9\_mc,  
l10\_mc, l11\_mc, l12\_mc, l13\_mc, l14\_mc, l15\_mc, l16\_mc, l17\_mc, l18\_mc,  
l19\_mc, l20\_mc, l21\_mc, l22\_mc, l23\_mc, l24\_mc, l25\_mc, l26\_mc, l27\_mc,  
l28\_mc, l29\_mc, l30\_mc, l31\_mc, l32\_mc, l33\_mc, l34\_mc, l35\_mc, l36\_mc];

debugText=“Pressed movieclip nr:”;

for(var l=1; l\<37; l++){  
letterArray[l].gotoAndStop(l+1);  
letterArray[l].onPress=function(){  
debugText=debugText+ " "+l;  
}  
}

* * *

debugText outputs:  
Pressed movieclip nr: 36 36 36 36 36 36

No matter what clip i press, i get the same output: 36.  
why?  
what can i do about it?

Thanks in advance!
