AttachMovieClip in AS3 - How to store a value

Hi,

I am new to AS3. I wanted to use attachMovieClip sort of thing in AS3. Basically I have a movieclip in library and the mc contains a textfield named “textName_txt” and I want to duplicate that movieclip with different text names.

I have done it using an Array and for loop. Everything is working fine till now. But I want to trace the movieclip number when I click on the movieclips. For example, I want to trace 0 when I click on first movieclip then 1 for second movieclip etc.

We could do this easily using AS2 where we could provide an instance name for movieclips using AttachMovieClip.

In AS3 I don’t know how to store the value of i(for loops i). It is always tracing 3 (the last number) for i because the length of Array is 4.

var names:Array = new Array("Ravi","Shyam", "Rahul", "Vineet");
for (var i:int = 0; i<names.length; i++) {
    var storei:int = i;
    var myBox:box_mc = new box_mc;
    myBox.x=20;
    myBox.y=40*i;
    myBox.textName_txt.text = names*;
    this.addChild(myBox);
    myBox.addEventListener(MouseEvent.CLICK, clicked);
}

function clicked(event:MouseEvent):void {
    trace("something "+this.storei);
}

Please let me know if I am not clear