Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to close a ScriptUI element?

  • How to close a ScriptUI element?

    Posted by Joshua Faget on September 14, 2016 at 2:15 am

    Hello,

    I’ve searched everywhere on the internet regarding this, but found nothing at all…

    I have this little script that when you launch it it has a button… when you click it, another one pops below it.
    I want every generated button to disappear on click. So far I’ve got it to “hide” … which is not the same, because if I make one, hide it and make another one… it will appear in the place of the second generated button… since the first one stays there, its just hidden.

    I hope you understood my question…

    Thanks for being such an amazing community.

    var myWin = new Window("palette", "Window", undefined,);
    var run = myWin.add("button", undefined, "MakeButton");

    run.onClick = function(){ //activate on click
    var btn = myWin.add("button", [0,0,30,30] , 'Hide'); //the new button
    btn.onClick = function(){btn.hide()}; //the action of the new button

    myWin.layout.layout(true);
    myWin.show();

    }
    myWin.center();
    myWin.show();

    Joshua Faget replied 9 years, 8 months ago 2 Members · 3 Replies
  • 3 Replies
  • Xavier Gomez

    September 14, 2016 at 6:35 am

    Use the .remove method of the parent (here the window itself) of the element to remove (the button):

    theParent.remove(theChild)
    or
    theParent.remove(theChildIndex) (theChildIndex is an integer in the range [0, theParent.children.length-1])

    btn.onClick = function(){
    this.parent.remove(this);
    myWin.layout.layout(true);
    myWin.layout.resize();
    };

    Xavier

  • Joshua Faget

    September 14, 2016 at 6:14 pm

  • Joshua Faget

    September 14, 2016 at 6:31 pm

    Thank you very much…

    While my post was pending review, I’ve figured out a way to do it by resizing it to 0, but your solution is much more elegant.
    I tried it before, but couldn’t figure out exactly how it works…

    Thanks a bunch.

    alert('Thank You') // :D

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy