I have an array of button names. I am dynamically adding them to aftereffects ui window with for loop. Now I need to ad event for each button, that event should alert clicked buttons text. But the problem is that no matter what button I click, I always get last buttons text. I know that ir is because I have an event for button witch in the last loop is the third button. But how can I make it alert the clicked buttons text. I am stuck in this for few days, and have no idea how to move forward.
This is the basic variation of my script, please help..
var buttons = ["one", "two", "three"];
var window = new Window("palette", "My window", undefined);
window.orientation = "column";
for (i = 0; i < buttons.length; i++) {
var button = window.add("button", undefined, buttons[i]);
button.onClick = function() {
alert(button.text)
}
};
window.center();
window.show();
This is the result: I clicked button "one". And it alerted "three". Though I want it to alert "one": result_pic