# Create function in for loop

**URL:** <https://forum.kirupa.com/t/create-function-in-for-loop/320968>\
**Category:** flash\
**Created:** [April 7, 2011, 12:56am UTC](https://forum.kirupa.com/t/create-function-in-for-loop/320968 "2011-04-07T00:56:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Safe](https://avatars.discourse-cdn.com/v4/letter/s/a4c791/32.png) [@Safe](https://forum.kirupa.com/u/Safe)\
**Post date:** [April 7, 2011, 12:56am UTC](https://forum.kirupa.com/t/create-function-in-for-loop/320968/1 "2011-04-07T00:56:37Z")

</div>

How would one go about creating a function inside a for loop that does not have a button action attached to it while still having access to the current index number.

This code was found on [senocular](http://www.senocular.com/flash/tutorials/faq/#loopfunctions):

```auto
var curr_button; for (var i=1; i<=3; i++){
    curr_button = this["button"+i];
    curr_button.num = i;   
    curr_button.onRelease = function(){ 
        trace(i); // would trace 4 for each button
        trace(this.num); // the value of i when the onRelease was created 
} 
}

```

This is all great however i would like the functions to just be regular old functions, not button actions (onPress), is this possible?

Thanks, lurker here for years.
