# Creating a function inside of a loop

**URL:** <https://forum.kirupa.com/t/creating-a-function-inside-of-a-loop/323177>\
**Category:** flash\
**Created:** [June 20, 2011, 2:28am UTC](https://forum.kirupa.com/t/creating-a-function-inside-of-a-loop/323177 "2011-06-20T02:28:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![legojoey17](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@legojoey17](https://forum.kirupa.com/u/legojoey17)\
**Post date:** [June 20, 2011, 2:28am UTC](https://forum.kirupa.com/t/creating-a-function-inside-of-a-loop/323177/1 "2011-06-20T02:28:05Z")

</div>

I was wondering if you could create functions using a loop, like so with just the !HERE! replaced with the method of creating it with the ‘i’ variable. Both the function name in the event listener and the function’s setting need to make use of the i variable. Thanks, Lego.

```auto
for (var i:int = 0; i <= 5; i++){
this["question"+i].addEventListener(MouseEvent.CLICK, !HERE! );
function !HERE! (e:MouseEvent):void{
//Function code here
}

```
