Variable Function Names
What I'm trying to do is add event listeners for each position up to the total of compPositions. This way, each one will have a dymanic function name. Right now, they all launch function "clicked1" but I can't figure out how to make it add numbers to the function name dynamically. Is there a different method I should be using to accomplish this goal?
Right now, compPosition = 5 so it should create 5 event listners, but I want them each to have their own function they exucute.
var i;
for (i = 1; i < compPositions +1; i++)
{
currentPos = "pos" + i;
this["pos" + i].addEventListener(MouseEvent.CLICK, clicked1)
}
Edit:
Actually, after thinking about it, I think this is a better approach, but I'm not sure how to pass over a variable using a click event.
var i;
for (i = 1; i < compPositions +1; i++)
{
var currentPos; //now it's private to this for loop
currentPos = "pos" + i;
this["pos" + i].addEventListener(MouseEvent.CLICK, posClicked)
}
In this version, I just need to pass over the currentPos variable to the function, but I'm not sure if that's possible.
Thanks,
Corey
