# Simple array question in as3

**URL:** <https://forum.kirupa.com/t/simple-array-question-in-as3/268959>\
**Category:** flash\
**Created:** [August 20, 2008, 9:58pm UTC](https://forum.kirupa.com/t/simple-array-question-in-as3/268959 "2008-08-20T21:58:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisef](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@chrisef](https://forum.kirupa.com/u/chrisef)\
**Post date:** [August 20, 2008, 9:58pm UTC](https://forum.kirupa.com/t/simple-array-question-in-as3/268959/1 "2008-08-20T21:58:52Z")

</div>

Hi all here’s a simple array question.

/\* as start \*/  
var arr:Array = [“1”, “2”, “3”];  
var btnSpace = 50;

for each (var s:Number in arr) {

```
var btn_mc:MovieClip = new MovieClip();
btn_mc.graphics.beginFill(0xcc0000);
btn_mc.graphics.drawRect(0,30* s,20, 20);
btn_mc.name = "btn_mc"+[COLOR=Red]s[/COLOR];
trace(btn_mc.name);
btn_mc.addEventListener(MouseEvent.CLICK, numIt);
btn_mc.graphics.endFill();
btn_mc.buttonMode = true;
stage.addChild(btn_mc);

function numIt(evt:MouseEvent) {
    //this function needs to return corresponding s from arr:Array
   [COLOR=Red] trace("clicked"+btn_mc.name);[/COLOR]

}

```

}

/\* as end \*/

I’m trying to get the btn\_mc to return the [COLOR=Red]s[/COLOR] value when clicked. So btn\_mc1 returns 1, btn\_mc2 returns 2 and btn\_mc3 returns 3. Putting the function numIt seemed like the logical way to me but it doesn’t work. trace btn\_mc.name gives the right names but I can’t get this action onto the btn\_mc, it just traces the last value.

Can anyone out there point me in the right direction on this.

Thanks for looking
