Copy link to clipboard
Copied
I have three questions, which I hope to illustrate through the following Dialog window.
var window1 = new Window ("dialog");
var input1 = window1.add ("edittext", undefined, "0");
var input2 = window1.add ("edittext", undefined, "0");
var button1 = window1.add ("button", undefined, "Add");
button1.onClick = function () {
alert (Number(input1.text) + Number(input2.text));
window1.close ();
}
window1.show ();
1. The JavaScript Tools Guide defines a Dialog window as "Holds focus when shown, does not allow activity in other application windows until dismissed." But in my example above, the alert message is shown before the Dialog is closed/dismissed. (I can make separate callbacks for alert() and close(), have alert() before close() and still the alert message is shown before the Dialog is closed.) What am I missing?
2. Why does show() have to be at the end? If I move button1.onClick after show(), it won't work.
3. Least salient, but most frustrating, because I don't get it: What is the relashionship between close() and show()? The Tools Guide says:
- close([result]), where result is "a number to be returned from the show method that invoked this window as a modal dialog."
- show(). "For a modal dialog, opens the dialog and does not return until the dialog is dismissed. If it is dismissed via the close() method, this method returns any result value passed to that method. Otherwise, returns 0."
Is anyone able to explain this better?
Thanks in advance.
1. when it says it doesn't allow activity, it means the user can not interact with the host application, i.e. Illustrator (you can't click on objects or menus). The script itselft does interact with the scripting engine and the appication. Does that help or did you mean something else?
2. The script executes each line from top to bottom. When it finds the show() method, it does that, it shows the window and waits for the user to take some action. At that point button.onClick has not loaded yet
...Copy link to clipboard
Copied
Hi, well...
1. alert() can be called from the main code and from the ui code.
You could write
button.onClick = function() {
win.close(1);
}
if(window1.show())
alert (Number(input1.text) + Number(input2.text));2. the show() returns when the window is closed. At that time defining button action is a bit late.
3. About return value: imagine a panel with two action buttons and a cancel button. ll three buttons would close the window and send a value. The remainder of the script would use the result of show() to know what to do.
Copy link to clipboard
Copied
"alert() can be called from the main code and from the ui code."
Can you elaborate, please?
Copy link to clipboard
Copied
Salut!
// JavaScript Document
var window1 = new Window ("dialog","Add", undefined);
var input1 = window1.add ("edittext", undefined, "");
input1.size = [50,18 ];
input1.active = true;
var input2 = window1.add ("edittext", undefined, "");
input2.size = [50,18 ];
var button1 = window1.add("button",undefined,"Add",{name: "ok"});
var result = window1.add ("edittext", undefined, "");
result.size = [50,18 ];
button1.onClick = function () {
result.text = Number(input1.text) + Number(input2.text);
input1.active = true;
}
window1.show ();
de elleere
Copy link to clipboard
Copied
Thanks. Nice. But my goal is to understand the behaviour of the window/functions.
Copy link to clipboard
Copied
Si cela peut aider ?
var window1 = new Window ("dialog","Add", undefined);
var input1 = window1.add ("edittext", undefined, "");
input1.size = [50,18 ];
input1.active = true;
var input2 = window1.add ("edittext", undefined, "");
input2.size = [50,18 ];
var button1 = window1.add("button",undefined,"Add",{name: "ok"});
var result = window1.add ("edittext", undefined, "");
result.size = [50,18 ];
button1.onClick = hasBtnsCbOnClick;
window1.show ();
//-------------
function hasBtnsCbOnClick() {
result.text = Number(input1.text) + Number(input2.text);
input1.active = true;
}
Copy link to clipboard
Copied
1. when it says it doesn't allow activity, it means the user can not interact with the host application, i.e. Illustrator (you can't click on objects or menus). The script itselft does interact with the scripting engine and the appication. Does that help or did you mean something else?
2. The script executes each line from top to bottom. When it finds the show() method, it does that, it shows the window and waits for the user to take some action. At that point button.onClick has not loaded yet so no action is taken.
3. [result] or anything in square brakets means optional, you don't have to supply a value. So you can use close() or close(55).
the relationship between close() and show() is that close(value) passes "value" to the show() function.
win.close(66);
var myNumber = win.show();
alert(myNumber); // -> returns 66
you don't have to use the ruturn value, but the functionality is there. You could use it to do an additional task right before closing the window like saving preferences or if you have many buttons that close the window you can identify which button sent the close request.
Copy link to clipboard
Copied
Thanks. That pretty much answers them.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more