# onPress Loop for Multiple MovieClips

**URL:** <https://forum.kirupa.com/t/onpress-loop-for-multiple-movieclips/144693>\
**Category:** Uncategorized\
**Created:** [April 16, 2005, 8:51am UTC](https://forum.kirupa.com/t/onpress-loop-for-multiple-movieclips/144693 "2005-04-16T08:51:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lecasn5](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@lecasn5](https://forum.kirupa.com/u/lecasn5)\
**Post date:** [April 16, 2005, 8:51am UTC](https://forum.kirupa.com/t/onpress-loop-for-multiple-movieclips/144693/1 "2005-04-16T08:51:26Z")

</div>

Hello, can anybody tell me what is wrong with this code.  
The problem is: everytime I press a movieClip, i -1(on the output window) should be equal to the number of the movieClip (ex: myClip17, when pressed, should produce in the output window a value of 17 for i-1).

Please copy paste this code to a flash document and you’ll see what I mean (please don’t forget that you have to have linkage in the library for a movieClip symbol that you have to create - it’s a circle only with stroke that has w=15 h=15).  
Every time I click on a number it should  
appear a circle on him. If the circle is already there it should disappear. But that’s not the case. Somehow every movieClip has the order to attach one of the instances of movieclip marca\_mc to myClip31.

var mcAcoplado = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];  
var diasDoMes = 31+1;  
var distEntreTexto = 10;  
for (i=1; i\<diasDoMes; i++) {  
\_root.createEmptyMovieClip(“myClip”+i, i);  
myClip = \_root[“myClip”+i];  
myClip.\_x = distEntreTexto;  
myClip.\_y = 50;  
distEntreTexto += 20;  
\_root.myClip.createTextField(“texto”, i, -8, -10, 17, 20);  
//texto = eval(“texto”+i);  
if (i\<10) {  
\_root.myClip.texto.text = “0”+i;  
} else {  
\_root.myClip.texto.text = i;  
}  
}  
for (i=1; i\<diasDoMes; i++) {  
myClip = \_root[“myClip”+i];  
\_root.myClip.onPress = function() {  
if (mcAcoplado[i-1] == false) {  
myClip.attachMovie(“marca\_lnk”, “marca\_mc”+i, 0);  
mcAcoplado[i-1] = true;  
} else {  
myClip[“marca\_mc”+i].removeMovieClip();  
mcAcoplado[i-1] = false;  
}  
trace(mcAcoplado[i-1]);  
trace(i-1);  
};  
}
