PDA

View Full Version : loop for identical functions



BF109
August 25th, 2008, 05:02 AM
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[i].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...