# AttachMovieClip in AS3 - How to store a value

**URL:** https://forum.kirupa.com/t/attachmovieclip-in-as3-how-to-store-a-value/303556
**Category:** flash
**Created:** [January 22, 2010, 7:32am UTC](https://forum.kirupa.com/t/attachmovieclip-in-as3-how-to-store-a-value/303556 "2010-01-22T07:32:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![black\_pearl](https://avatars.discourse-cdn.com/v4/letter/b/aeb1de/32.png) [@black\_pearl](https://forum.kirupa.com/u/black_pearl)
#### Post date: [January 22, 2010, 7:32am UTC](https://forum.kirupa.com/t/attachmovieclip-in-as3-how-to-store-a-value/303556/1 "2010-01-22T07:32:50Z")

</div>

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.

```auto
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
