# Assigning onPress functions in a loop

**URL:** <https://forum.kirupa.com/t/assigning-onpress-functions-in-a-loop/200891>\
**Category:** Uncategorized\
**Created:** [September 16, 2006, 6:17am UTC](https://forum.kirupa.com/t/assigning-onpress-functions-in-a-loop/200891 "2006-09-16T06:17:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonamos](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anonamos](https://forum.kirupa.com/u/anonamos)\
**Post date:** [September 16, 2006, 6:17am UTC](https://forum.kirupa.com/t/assigning-onpress-functions-in-a-loop/200891/1 "2006-09-16T06:17:08Z")

</div>

is that possible? i’m a complete beginner when it comes to flash and actionscript… so if it sounds like i dont know what i’m talking about… it’s because i don’t!

let me describe my situation…

I have about 20 boxes… and on each box i want to assign the onPress to trace the value corresponding to an Array at element “i” in the console…

instead of doing:

```auto
box1.onPress = function() {
  trace("the value is: "+hypotheticalArray[1]);
}

```

from 1 to 20… i’d like to loop these assignments.

like this:

```auto
function myTrace(i) {
  trace("the value is: "+hypotheticalArray*);
}

//assume that there are as many textboxes as there are elements in the array.
for (var i=0; i<hypotheticalArray.length; i++) {
  set("box"+i+".onPress",myTrace(i));
}

```

ANY suggestions would be greatly appreciated!
