Skip to main content
Participating Frequently
February 18, 2016
Answered

Procedure "window.close()" do not working corectly?

  • February 18, 2016
  • 3 replies
  • 1589 views

Hi Everyone!


I noticed that the procedure "window.close()" in my scripts is not working properly. This procedure works for the first time only.

// TWO WINDOWS TESTING

var win_1= new Window("palette", "Window 1",undefined);

var win_2= new Window("palette", "Window 2", undefined);

buildUI_window1();

buildUI_window2();

win_1.center();

win_1.show();

win_2.center();

function buildUI_window1() {

        win_1.btn = win_1.add("button", undefined, "SHOW WINDOW 2");

        win_1.btn.onClick = function() {

            win_2.btn.text = "CLOSE";

            win_2.show();

            }

    }

function buildUI_window2() {

        win_2.btn = win_2.add("button", undefined, "CLOSE");

        win_2.btn.onClick = function() {

            win_2.close();  // This window can be close at firt time only!

            }

    }

This script showing two windows.

At first time:

I open my second window click the "SHOW WINDOW 2" button  .

It opened.

In the second window click the "CLOSE" button.

It closed.

At second time:

I open my second window again.

It opened.

At this time, to close the "Window 2" will not work.

Caution! This second window can be removed only by closing the After Effects.

Thanks,

Sergio

This topic has been closed for replies.
Correct answer UQg

There is another thread in this forum mentionning this, but can't find it...: Since CC, a palette that has been closed can be shown again, it is fully responding, except that its "close" feature is broken.

A workaround is to :

(1) internally, not use win.close() but win.hide()

(2) hide the red cross button to the user: var win_2= new Window("palette", "Window 2", undefined, {closeButton: false});

and add a possibility for the user to hide the palette (eg with a button somewhere with myButton.onClick = function(){this.window.hide();});


It works fine, and if the script is launched again, you can retrieve your window fully working.


Xavier.

3 replies

UQg
Legend
February 18, 2016

Thanks for quoting answered, but that's only a workaround, that works.

I'd really like to know why the close behaviour has changed, if there is a plan to fix or if it's not even considered a bug...

Xavier.

Participating Frequently
February 18, 2016

Tnx, Xavier!

We have to work with what works) But this issue until cannot be considered closed.

Sergio

UQg
UQgCorrect answer
Legend
February 18, 2016

There is another thread in this forum mentionning this, but can't find it...: Since CC, a palette that has been closed can be shown again, it is fully responding, except that its "close" feature is broken.

A workaround is to :

(1) internally, not use win.close() but win.hide()

(2) hide the red cross button to the user: var win_2= new Window("palette", "Window 2", undefined, {closeButton: false});

and add a possibility for the user to hide the palette (eg with a button somewhere with myButton.onClick = function(){this.window.hide();});


It works fine, and if the script is launched again, you can retrieve your window fully working.


Xavier.

Alan_AEDScripts
Inspiring
February 18, 2016

I came across this info online.... might help.

“Nested” modal dialogs

The following sequence of operations using dialog (modal) windows is illegal, and will result in an

application crash (assuming the script created two separate dialog windows - win1 and win2):

var result1 = win1.show();

win1.hide();

/* Create and show a nested dialog */

var result2 = win2.show();

win2.close();

win1.show();

win1.close();

As noted in the JavaScript Tools Guide document, calling hide() for a dialog window does not only

change the window's visibility; it is equivalent to calling close(0), which removes the window from its

modal state. If the script calls show() a second time for this window to make it visible again, the

application is likely to crash when the window is finally closed. If your script requires the use of "nested"

modal dialogs, use a sequence like this instead:

var result1 = win1.show();

/* Create and show a nested dialog */

var result2 = win2.show();

win2.close();

win1.close();