Open GoogleCodeExporter opened 9 years ago
Basically you need to use a different function for each button. There is a
couple ways you can do this.
If you are looping through an array of data to create the buttons you could add
the functions to that/an array also. eg.
{{{
for (i in 0...5)
{
buttons[i] = Button(up[i], over[i], buttonClickFun[i]);
}
}}}
or you can create an individual function inside the loop that calls your single
onClick function with a unique id or something eg.
{{{
var self = this;
for (i in 0...5)
{
var buttonId = i;
buttons[i] = Button(up[i], over[i], function () { self.onButtonClick(buttonId); } );
}
}}}
You need to create the extra variable (buttonId) inside the loop as the Id, it
won't work properly if you use i directly (because it keeps changing in
subsequent iterations)
Hope that helps you out (sorry if the code formatting is bad, first time i've
tried posting code in a comment)
Original comment by lyndon.h...@yahoo.com.au
on 14 Jul 2010 at 2:42
Thanks very much!
I was missing the extra variable inside the loop.
Original comment by nik...@gmail.com
on 19 Jul 2010 at 12:35
Original issue reported on code.google.com by
nik...@gmail.com
on 15 May 2010 at 4:05