Dynamically assign listeners to buttons?
I've got a set of buttons in a scene that I want to dynamically assign listeners to. The purpose of the buttons is to direct the user to a frame (different per button) in a different scene (same for all buttons). Here's the code I'm using:
listener = new Object();
listener.click = function (event) {
gotoAndStop("Scene2", 1);
}
this["button1"].addEventListener("click" , listener);
I'm having to do this for each button, replacing the frame number and the number in the button name each time. I figure there should be a way to do this dynamically, where I maybe use a "for..." loop to assign a listener to each button. I keep running into a problem with variable scope, though, whether or not I stick the current number in a _root variable.
Any ideas?
listener = new Object();
listener.click = function (event) {
gotoAndStop("Scene2", 1);
}
this["button1"].addEventListener("click"
I'm having to do this for each button, replacing the frame number and the number in the button name each time. I figure there should be a way to do this dynamically, where I maybe use a "for..." loop to assign a listener to each button. I keep running into a problem with variable scope, though, whether or not I stick the current number in a _root variable.
Any ideas?
