4 Replies Latest reply: Jan 8, 2014 10:22 AM by zipkiev RSS

    Super easy checkbox script, but not work!!!!

    zipkiev Community Member

      Hi, super easy checkboxing script, but don't work, need help

      exemple:

      first i add checkbox to my gui panel by this:

      var checkbox1= some_panel.add("checkbox", undefined, "checkbox1");

      and set it cheked by this:

      checkbox1.value=true;

      // there are some not interesting code....... and then i need checked it on true/false in my function inside other function,so:

      function test1()

      {

      myProperty = app.project.activeItem.selectedLayers[0].property("position");

      convertToKeyframes(myProperty);

                function convertToKeyframes(theProperty)

                {

                if(checkbox1.value==true) //this is now work!!!!!!!!!!!!

                {

                do my stuff;

                }

      }

        • 1. Re: Super easy checkbox script, but not work!!!!
          David Torno Community Member

          For a variable to be used inside a function, it would need to be declared within the function or passed into it.

          function test1(myCheckbox){

               myProperty = app.project.activeItem.selectedLayers[0].property("position");

               convertToKeyframes(myProperty);

               function convertToKeyframes(myCheckbox, theProperty){

                    if(myCheckbox.value==true){

                         do my stuff;

                    }

               }

          }

          • 2. Re: Super easy checkbox script, but not work!!!!
            zipkiev Community Member

            thx for reply but, i try and it not work... i think i can't transfer data from this

            var checkbox1= some_panel.add("checkbox", undefined, "checkbox1");

            checkbox1.value=true;

            to this

            function test1(myCheckbox)

            {

             

            }

             

            i try do something like this

            var Button4= some_panel.add("button", undefined, "ExpToKey");

            Button4.onClick=test1(checkbox1); and not work.

             

            PS can i use global names, other?, i try(public) but AE script give me error, for now it is to many work to add just a checkbox....

            • 3. Re: Super easy checkbox script, but not work!!!!
              cswaim080880 Community Member

              Hi zipkiev,

               

              Technically speaking, since checkbox1 is declared at the global scope, the function test1 will have access to it.  You shouldn't need to pass it to test1.  The only way it wouldn't work is if you tried to access a variable defined within a function at the global scope level...but even that can work in ways that are unexpected.  Javascript can be a little funky about scope and in general you may find that even though your accessing an object that is out of "scope" for that function...it could still work as expected. Javascript is a very forgiving language which can make finding the route cause of a problem hard.  In addition, the way you attempted to pass it to the onClick eventHandler will not work.  That is looking for a Function instance...not a function call.  The only thing passed to the event handler is the Event object which is passed to it at the system level (unable to override).

               

              Would you feel comfortable sharing your full code so we might help debug it?

               

              I created a script to test out exactly what you did...here's what mine was

               

              var some_panel = new Window("palette", "Test", undefined, {resizeable: true});

              var checkbox1= some_panel.add("checkbox", undefined, "checkbox1");

              checkbox1.value=true;

               

              function test1() {

                  myProperty = app.project.activeItem.selectedLayers[0].property("position");

                  convertToKeyframes(myProperty);

              }

               

              function convertToKeyframes(theProperty) {

                  if(checkbox1.value==true) {

                      alert("it's true");

                  }

              }

               

              var button = some_panel.add("button", undefined, "Test");

              button.onClick = test1;

               

              some_panel.show();

               

               

              When I run this, I get the checked value properly when it gets to "checkbox1.value == true" so there could be some other issue with your script.  One thing I noticed about the code you posted was that you did not close the Function definition for function test1 with a closing curly brace.  That would account for the code not running at all (but not a runtime issue).

               

              If you can post your entire script, I could give better feedback...but hopefully this helped!


              Calvin

              • 4. Re: Super easy checkbox script, but not work!!!!
                zipkiev Community Member

                thx guys  for reply , i find a problem..  the problem is that I declare a variable in a function where i create a window(pallet with buttons), and other variables(from other functions) cant see this checkbox inside this function...  everything was decided very simply by shifting the  variables where i later put checkbox in top of script(above other function) so now everyone could see checkbox.

                 

                Sorry for bad English