I am trying to assign events to a bunch of buttons at once. To test out to see if my theory works i tried this code with 3 buttons on the stage named test1, test2, ect.
var e=0
while(e!=4){
_level0["test"+e].onRelease = function() {
trace("tester"+e+"<<<")
};
e++
}
they each trace something, but its the same thing?! tester4<<<
Any ideas?
That happens because after the loop evaluates, the variable i will be equal 4, therefore clicking any button will return 4.
I think you want something like this:
while (e != 4) {
_level0["test"+e].onRelease = function() {
trace("tester"+this._name.substr(-1)+"<<<");
};
e++;
}
or
while (e != 4) {
_level0["test"+e].f = e;
_level0["test"+e].onRelease = function() {
trace("tester"+this.f+"<<<");
};
e++;
}
thanks excatly what i was looking for.