ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to detect multiple OK buttons in Script UI dialogue box

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Reuben Lara
How to detect multiple OK buttons in Script UI dialogue box
on Oct 17, 2018 at 12:37:00 am

In the code below, I can't seem to target which button was pressed. Both "Option 1" and "Option 2" should behave like OK buttons (do some code and close the window). What am I doing wrong? Thanks!

var myWindow = new Window ("dialog");
myWindow.add ('statictext', undefined, 'Mode:', {multiline: false});

// some more window input options

myWindow.add ("button", undefined, "Option 1", {name: "ok"});
myWindow.add ("button", undefined, "Option 2", {name: "ok"});
myWindow.add ("button", undefined, "CANCEL", {name: "cancel"});

if (myWindow.show () == 0) {
alert("You chose Option 1");
//execute some code and close the window
}
if(myWindow.show () == 1){
alert("You chose Option 2");
//execute some code and close the window
}
if(myWindow.show () == 2){
alert("You chose Cancel");
exit ();
}


Return to posts index

Dan Ebberts
Re: How to detect multiple OK buttons in Script UI dialogue box
on Oct 17, 2018 at 6:12:15 am

I'm not sure how it's supposed to work, but it seems like you could set up a unique onClick function for each button, or direct them all to the same function, but have unique names for each button (like "ok1","ok2", and "cancel") so the function can detect which button was clicked:


function button_click(){
if (this.name == "cancel"){
// do stuff
}else{
// do other stuff
}
}


Dan



Return to posts index

Reuben Lara
Re: How to detect multiple OK buttons in Script UI dialogue box
on Oct 17, 2018 at 7:36:06 pm

Thanks for the ideas. Tried them and they didn't respond as expected. In the end, it turns out ScriptUI dialogues can only have one default "OK" button and one default "cancel" button where the window returns either "1" or "0" for OK and Cancel respectively. Script UI detects if the "name" is "ok" or "cancel" to give those buttons default functionality. If multiple buttons have a "name" of "ok", then only the first one is recognized. So, to add additional buttons that behave like the OK button (i.e. do some code and close the window), see below:

var myWindow = new Window ("dialog");
myWindow.add ('statictext', undefined, 'Mode:', {multiline: false});

// some more window input options

var additionalOKbutton = myWindow.add ("button", undefined, "Option 1", {name: "option01"});
myWindow.add ("button", undefined, "Option 2", {name: "ok"});
myWindow.add ("button", undefined, "CANCEL", {name: "cancel"});

additionalOKbutton.onClick = function (){
//execute some code
//close window
myWindow.close();
}

if (myWindow.show () == 1) {
alert("You chose Option 2");
//execute some code
//window closes automatically
}else{
alert("You chose Cancel");
//execute some code
exit ();
//window closes automatically
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]