I am looping through and creating a random number of dynamic objects. I am trying to create an click addEventListener that will trace the name property of the object being clicked. Here is my script:
var xSpacing:int = new int;
var textArray:Array = new Array;
for (var i:int = 1; i < 10; i++){
textArray* = new TextField;
with(textArray*){
text = i;
height = 20;
width = 20;
x = xSpacing;
y = 0;
name = "box" + i;
}
addChild(textArray*);
textArray*.addEventListener(MouseEvent.CLICK, function(event){ numberClicked(textArray*); });
xSpacing=xSpacing+50;
}
public function numberClicked(o:Object){
trace(o.name);
}
When clicked the it tries to trace the next object (object 11) instead of tracing the one being clicked. How do I make the addEventListener unique to each instance?
Thanks