Obtain value of Toggled IconButton via Script
Hi community, good afternoon, can anybody help me with this code?
I am trying to get the value of the selected button, I am using icon buttons because I need to show in the UI how is the color, however when I try to get the value or the position of [i] in which is selected for some reason it always returns the number "11". I have 33 images in the folder and I split it in three columns so I dont have a large UI to pick (it is too big hehe)
I'll appreciate any help or suggestions:
var dir = Folder("C:\\Users\\USER\\Downloads\\Colors");
var files = dir.getFiles("*.png");
var w= new Window("dialog");
w.orientation= "row";
var seleccion = "";
var firstcolumn = w.add ("panel");
var secondcolumn = w.add ("panel");
var thirdcolumn = w.add ("panel");
firstcolumn.orientation = "column";
secondcolumn.orientation = "column";
thirdcolumn.orientation = "column";
for(var f = 0; f < files.length; f++){
while (f<11) {
firstcolumn.add ("iconbutton", undefined, files[f], {name: i, style: "toolbutton"});
f++;
}
while (f<22) {
secondcolumn.add ("iconbutton", undefined, files[f], {name: i, style: "toolbutton"});
f++;
}
thirdcolumn.add ("iconbutton", undefined, files[f], {name: i, style: "toolbutton"});
}
//Create button.
var botones = w.add("group");
// botones.orientation = "row";
botones.add ("button", undefined, "OK");
for (var i = 0; i < firstcolumn.children.length; i++) {
firstcolumn.children[i].onClick = function(){
alert(this.name);
}
}
// w.show ();
if(w.show() == 1){
alert(seleccion);
}
