Can't click on button in window created using ScriptUI
In Photoshop, using ExtendScript, I created a window using the code given in this link: https://github.com/Adobe-CEP/CEP-Resources/blob/master/ExtendScript-Toolkit/Samples/javascript/SnpCreateDialog.jsx
However, I am unable to click on the buttons in the window created, nor does the window stay open without adding a sleep statement in the function. Any ideas?
/**
@fileoverview Shows how to create a basic ScriptUI dialog.
@11203287 Shows how to create a basic ScriptUI dialog.
<h4>Usage</h4>
<ol>
<li>Run the snippet in the ExtendScript Toolkit (see Readme.txt).
This snippet can run in any application that supports ScriptUI.
<li>A dialog appears, which emits trace statements to the JavaScript console to indicate which button was pressed.
</ol>
<h4>Description</h4>
<p>Creates and shows a simple ScriptUI modeless dialog (also called a palette)
with OK/Cancel buttons and event listeners that implement the button behavior.<br ./>
@constructor Constructor.
*/
function SnpCreateDialog()
{
this.windowRef = null;
}
/**
Functional part of this snippet.
Create a window of type "palette" (a modeless dialog) and display it.
@Return True if the snippet ran as expected, false otherwise.
@TyPe Boolean
*/
SnpCreateDialog.prototype.run = function()
{
// Create a window of type palette.
var win = new Window("palette", "SnpCreateDialog",[100,100,380,245]); // bounds = [left, top, right, bottom]
this.windowRef = win;
// Add a frame for the contents.
win.btnPanel = win.add("panel", [25,15,255,130], "SnpCreateDialog");
// Add the components, two buttons
win.btnPanel.okBtn = win.btnPanel.add("button", [15,65,105,85], "OK");
win.btnPanel.cancelBtn = win.btnPanel.add("button", [120, 65, 210, 85], "Cancel");
// Register event listeners that define the button behavior
win.btnPanel.okBtn.onClick = function() {
$.writeln("OK pressed");
win.close();
};
win.btnPanel.cancelBtn.onClick = function() {
$.writeln("Cancel pressed");
win.close();
};
// Display the window
win.show();
return true;
}
/**
"main program": construct an anonymous instance and run it
as long as we are not unit-testing this snippet.
*/
if(typeof(SnpCreateDialog_unitTest) == "undefined") {
new SnpCreateDialog().run();
}
