Its probably an easy solution. But i have 61 buttons being generated for a level selection screen for a game i am making. and i need an onclick function for each of the buttons.
I would much prefer it if i didn't have to write a separate function for each of the 61 buttons and would prefer to do it in a loop or something. but every time i place it in a loop, i just get undefined outputs.
My current loop is this
Code:
for (var i = 1; i < onscreen.length; i++)
{
trace(levels[onscreen[i]]);
levels[onscreen[i]].onRelease = function():Void
{
trace(i);
loadTrack(onscreen[i]);
};
}
The onscreen array contains names of every one of the buttons. and has a length of 62 (number 1 is the main template screen, not a button hence why the loop starts at 1, not 0). But for some reason, every button i click on
returns a value of 62.
Any help would be greatly appreciated.