1 Reply Latest reply on Apr 14, 2008 10:48 AM by Bob, Adobe Engineer

    Understanding ScriptUI

      Hi all,

      I am playing around with ScriptUI using the sample script SnpCreateCheckBoxRadioButtons.jsx as a template. Despite running it step by step in debug mode I don't fully understand what is happening. I would really appreciate if someone has time to explain a couple of things.

      1) I have never really got my mind around this prototype thing. Why is it used here, whats the upside with it?

      2) new SnpCreateCheckBoxRadioButtons().run(); first runs the SnpCreateCheckBoxRadioButtons()
      and then jumps to SnpCreateCheckBoxRadioButtons.prototype.run = function(). Is it some kind of double call?

      3) Finally my main problem, where and how is the user input returned?

      I tried to collect the values in the win.quitBtn.onClick callback function but they don't "survive" to be returned by the return statement a couple of lines down, outside the onClick function.
      Putting values in variables defined at the top level of the script didn't seem to help.
      One peculiar thing, the values shows up in the console the second time the script is run.

      Gunno I
        • 1. Re: Understanding ScriptUI
          Level 1
          Email me at rstucky@starband.net, I have a an old Netscape JS guide that does a very good job of explaining objects and prototypes.

          Basically, you define class in JavaScript with a function:

          MyClass = function( that, theOther ) {
          this.that = that;
          this.theOther = theOther;

          If you now call: var x = new MyClass( 12, 15 );

          You will have an instance of a "MyClass" object.


          "x.that" will equal 12, "x.theOther" will equal 15.

          Now, if you want that class to have "methods" then you need the prototype statement.

          MyClass.prototype.product = function() {
          return this.that * this.theOther;

          If you did:

          var y = x.product();

          the value of "y" will now be 12 * 15, or 180.

          So, someplace in the code, they declare a class named "SnpCreateCheckBoxRadioButtons",


          give it a method named "run" using the

          SnpCreateCheckBoxRadioButtons.prototype.run = function(){

          Then new SnpCreateCheckBoxRadioButtons().run() will essentially, in a single call, create a new instance of the SnpCreateCheckBoxRadioButton class, and execute it's run method. And that's why the debugger jumps into that function.

          On the second question, you get values in a ScriptUI window from the window reference itself. The "onClick" function of the quit button will only hold those values as local while the function is running. Once the function is done, they go away.

          One simple way to do it (note code not tested at all):

          function makeWindow = function() {
          var w = new Window( "dialog", "Demo" );
          w.textBox = w.add( "edittext" );
          w.textBox.characters = 80;
          var group = w.add( "group" );
          group.alignChildren = ["right", "bottom" ];
          w.cancelButton = group.add( "button", undefined, "Cancel" );
          w.cancelButton.onClick = function() {
          this.window.close( 2 );
          w.okButton = group.add( "button", undefined, "OK" );
          w.okButton.onClick = function() {
          this.window.close( 1 );

          var w = makeWindow();
          if ( w.show() == 1 ) { // they clicked OK
          var text = w.textBox.text;
          /// do something cool with the text
          } else { // they clicked the cancel button
          // do whatever you need to do if they cancel