Skip to main content
zachneel
Participating Frequently
April 10, 2019
Question

Adding/Removing a scriptUI Group

  • April 10, 2019
  • 1 reply
  • 840 views

Here's my code:

dropSelec.onChange = function secOff()

        {

            if (dropSelec.selection==3)

            {

                if (offGroupMain.children.length==1)

                {

                var offGroupT=offGroupMain.add("group");

                var secOffOne = offGroupT.add ("statictext", undefined, "Offset Two:");

                var secOffTwo = offGroupT.add ("edittext");

                secOffTwo.characters = 5;

                secOffTwo.text="1";

                var secOffThree = offGroupT.add ("statictext", undefined, "frames");

                win.layout.layout(true); 

                }

             }

         if (dropSelec.selection!==3)

         {

            if (offGroupMain.children.length>1)

            {

             offGroupMain.remove(offGroupT);

             win.layout.layout(true);

             }

          }

         }

I'm trying to make it so that when my drop down menu is on a certain selection, it creates a new line in the UI, and removes it when changed to anything else.

Right now it is both adding and removing the line when I switch to the specified selection.

This topic has been closed for replies.

1 reply

Tomas Sinkunas
Legend
April 11, 2019

The issue with your snippet is that variable offGroupT is undefined on line 20.

Change it to offGroupMain.children[1] and it will work.

if (dropSelec.selection == 3) {

    if (offGroupMain.children.length == 1) {

        var offGroupT = offGroupMain.add("group");

        var secOffOne = offGroupT.add("statictext", undefined, "Offset Two:");

        var secOffTwo = offGroupT.add("edittext");

        secOffTwo.characters = 5;

        secOffTwo.text = "1";

        var secOffThree = offGroupT.add("statictext", undefined, "frames");

        win.layout.layout(true);

    }

} else {

    if (offGroupMain.children.length > 1) {

        offGroupMain.remove(offGroupMain.children[1]);

        win.layout.layout(true);

    }            

}