# Using array data as button list

**URL:** <https://forum.kirupa.com/t/using-array-data-as-button-list/246573>\
**Category:** Uncategorized\
**Created:** [December 12, 2007, 2:01pm UTC](https://forum.kirupa.com/t/using-array-data-as-button-list/246573 "2007-12-12T14:01:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GBear](https://avatars.discourse-cdn.com/v4/letter/g/e9a140/32.png) [@GBear](https://forum.kirupa.com/u/GBear)\
**Post date:** [December 12, 2007, 2:01pm UTC](https://forum.kirupa.com/t/using-array-data-as-button-list/246573/1 "2007-12-12T14:01:14Z")

</div>

hoping this has a simple solution, basically i have an array that holds MC names and i want to use a loop so when i click on any of these buttons they will perform a function. for the testing i basically get them to trace a message, heres what i got:

there a loop that pushes data from another ‘generator’ into an array called ‘randomButton’  
but basically its like:  
randomButton[0] = “\_root.rightgrid\_1”  
…etc…etc… there are only 5 items in this array.  
but heres what i got:

```auto

var randomButton:Array = new Array()

for (var i=0;i<randomButton.length;i++){
     randomButton*.onRelease = function(){
            trace("PING")
     }
}

```

it doesn’t work, but when i test if the buttons will work with the following it code, it works.

```auto

_root.rightgrid_1.onRelease = function(){
trace("PING")
}

```

what am i doing wrong?
