9 Replies Latest reply on Nov 19, 2014 5:31 AM by Harbs.

    Why does closing a window in Indesign doesn't work?

    Stamm Level 1

      I have a question concerning Indesign script.

      Why does it work, when you close a window like:

      submitButton.onClick = function(){ close(); }

      But when I try to execute a function afterwards like:

      submitButton.onClick = function(){ close(); tagElements(); }

      (note I am using the "with" tag, so no window.close() is needed)

      The window does not close? Am I forgetting about something here? Shouldn't the window close, and then execute the function?

      The window is initialized like:

      var de = new Window('dialog', 'Descriptions');
        • 1. Re: Why does closing a window in Indesign doesn't work?
          Trevorׅ Adobe Community Professional

          Stamm wrote:

           

          (note I am using the "with" tag, so no window.close() is needed)

          The window is initialized like:

          var de = new Window('dialog', 'Descriptions');

          O.k. but did you see if it does work when you use de.close() ?

          • 2. Re: Why does closing a window in Indesign doesn't work?
            Stamm Level 1

            Hey, sadly doesn't work. I've put the "close" tag outside of the "with" function now and it's still the same error.

            • 3. Re: Why does closing a window in Indesign doesn't work?
              Trevorׅ Adobe Community Professional

              Try minimizing the script (ON A BACKUP) to the point where you no longer get the problem or you still get the problem and then post the script here

              • 4. Re: Why does closing a window in Indesign doesn't work?
                Stamm Level 1

                Hey, I think this does not solve the problem...

                 

                   var ds = new Window('dialog');

                   buttonnew = ds.add('button', undefined, 'submit');

                   buttonnew.onClick = function(){

                       ds.close();

                       newwindow();

                   }

                ds.show();

                 

                   function newwindow(){

                   var de = new Window('dialog');

                   buttonnew2 = de.add('button', undefined, 'submit');

                   buttonnew2.onClick = function(){

                       de.close();

                       dosth();

                   }

                   de.show();

                }

                 

                function dosth(){

                       alert('test');

                   }

                 

                If you test this, you will see, that every time, something new is executed, the old window doesn't close first. For example, you open the second dialog with the function, the first one doesn't close, after this you execute the function, the "dosth()" is being executed, and THEN the window is being closed...

                 

                A working solution would be, to use all of this stuff inside functions and use global variables to pass in data. It's just strange to me, that this does not work without having to wrap everything inside functions. In my feeling , it should somehow be possible?

                • 5. Re: Why does closing a window in Indesign doesn't work?
                  Trevorׅ Adobe Community Professional

                  Yep this is a difference between the way CS and CC handle dialog modules.

                  CS does what you want and CC does not.

                  This is not the only example you can find of this

                   

                  You can the function as an object to pass data i.e. instead of var de = .... you could use newwindow.de = .... this can sometimes have advantages over globals, for example keeping track of the variables origin and the ability to delete it.

                   

                  You could of course use palettes or windows instead of dialogs with those you do not have this problem.

                   

                  Maybe someone else has some better ideas.

                  • 6. Re: Why does closing a window in Indesign doesn't work?
                    Harbs. Level 6

                    Here's the pattern I use:

                     

                      var ds = new Window('dialog');
                       buttonnew = ds.add('button', undefined, 'submit');
                       buttonnew.onClick = function(){
                           ds.close(1);
                       }
                    if(ds.show()){
                      newwindow();
                    }
                    
                       function newwindow(){
                       var de = new Window('dialog');
                       buttonnew2 = de.add('button', undefined, 'submit');
                       buttonnew2.onClick = function(){
                           de.close(1);
                       }
                       if(de.show()){
                         dosth();
                    }
                    }
                    
                    function dosth(){
                           alert('test');
                       }
                    
                    • 7. Re: Why does closing a window in Indesign doesn't work?
                      Trevorׅ Adobe Community Professional

                      Well that is the much more normal and sensible way of doing it.

                      I have done that sort of thing very many time and can't work out why I didn't think of it for this thread.

                      • 8. Re: Why does closing a window in Indesign doesn't work?
                        Stamm Level 1

                        Thank you really much! I have two questions regarding this. Why do you have to use "close(1)" over "close()"? And secondly: Why is if(de.show()) true, after you close the window? I would figure, it's true when the window is active, and not in the moment its being closed?

                        • 9. Re: Why does closing a window in Indesign doesn't work?
                          Harbs. Level 6

                          Window.close() returns the value you pass to the caller.

                           

                          So passing 1 (or true) causes the "if" to pass the test. Passing 0 or false would cause it to fail. I believe passing nothing would also cause it to fail.

                           

                          If I'm not mistaken this is only the case to modal dialogs. Palettes behave differently.

                           

                          Harbs