-
Possible to make a iconbutton that toggles its image?
Currently having issues in making a toggle iconbutton with onClick(),
here’s what I have
var img1 = image 1's file path
var img2 = image 2's file path// v - just the UI
(function(thisObj) {scriptBuildUI(thisObj)
function scriptBuildUI(thisObj) {
var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Expression2button_V01.2", undefined, 0);var button = win.add("iconbutton",[0,0,30,30],img1);
//----
button.onClick = function(){
if(button.image = img1){
button.image = img2;
}else{//problematic part, after the 1st onClick and the image changes to img2, when you click again it doesn't go to this else statement
button.image = img1;
}//UI end code v --
win.onResizing = win.onResize = function() {
this.layout.resize();
};win instanceof Window
? (win.center(), win.show()) : (win.layout.layout(true), win.layout.resize());
}})(this);
===================================found a fix, had to make a state by using boolean
var butState = true;
button.onClick = function(){
if(butState){
button.image = img2;
butState = false;
}else{
button.image = img1;
}
Sorry, there were no replies found.