I am working with pictures. I want someone to pick one of three. The pictures will be held in movieclips.
var container0:MovieClip = new MovieClip();
var container1:MovieClip = new MovieClip();
var container2:MovieClip = new MovieClip();
Intially they have an alpha of 0. I want them to all of appear at once. I use the following code to make them appear. This code does not have a problem. It works.
for (var b:int = 0; b < 3; b++) {
this[“container”+b].alpha = 1;
}
I then need to add an event listener to listen for the mouse click. I want to use a loop.
for (var b:int = 0; b < 3; b++) {
this[“container”+b].addEventListener(MouseEvent.CLICK, evaluation);
}
But when I do it this way I get the following error.
TypeError: Error #1010: A term is undefined and has no properties.
at MethodInfo-6()
The code: var container0:MovieClip = new MovieClip(); is at line 6.
If I use the following code all works well.
container0.addEventListener(MouseEvent.CLICK, evaluation);
container1.addEventListener(MouseEvent.CLICK, evaluation);
container2.addEventListener(MouseEvent.CLICK, evaluation);
I know the simple answer is to use the code that works but I would like to do it with a loop because I want to vary the number of pictures.
Any help is greatly appreciated. Thanks … Michael