# Loop for identical functions

**URL:** https://forum.kirupa.com/t/loop-for-identical-functions/269241
**Category:** Uncategorized
**Created:** [August 25, 2008, 8:02am UTC](https://forum.kirupa.com/t/loop-for-identical-functions/269241 "2008-08-25T08:02:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![BF109](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@BF109](https://forum.kirupa.com/u/BF109)
#### Post date: [August 25, 2008, 8:02am UTC](https://forum.kirupa.com/t/loop-for-identical-functions/269241/1 "2008-08-25T08:02:28Z")

</div>

Let say i have two arrays:one with some textButt(doesent matter)  
and one were my functions are push

var textButt:Array = new Array();  
var functions:Array = new Array();

and one array with contents wich i use in textButt…

var texts:Array = new Array(“meniu a”, “meniu b”, “meniu c”,…);

Now:i need to create a loop for the three (or could be as many i need…let say  
i \< texts.length) identical functions down below…

function functia0(evt:MouseEvent):void {  
textButt[0].setTextFormat(textFormatOver);//or no matter what aditional content//  
}  
functions.push(functia0);

function functia1(evt:MouseEvent):void {  
textButt[1].setTextFormat(textFormatOver);//or no matter what aditional content//  
}  
functions.push(functia1);

function functia2(evt:MouseEvent):void {  
textButt[2].setTextFormat(textFormatOver);//or no matter what aditional content//  
}  
functions.push(functia2);

with an event listener (no problem with this…)

for (var j:Number = 0; j \< texte.length; j++) {  
butoane[j].addEventListener(MouseEvent.ROLL\_OVER, functiile[j]);  
}

i need to know if it is posible to write something like

for (var i:Number = 0; i \< texte.length; i++) {  
function functia"i"(evt:MouseEvent):void {  
textButt\*.setTextFormat(textFormatOver);//or no matter what aditional content//  
}  
functions.push(functia"i");  
}

of course functia"i" is wrong, but i just cannot find a way to write all this…
