6 Replies Latest reply on Jun 14, 2017 8:05 AM by jportell25

    Introducing multiple functions in Extendscript

    jportell25 Level 1

      I have been doing my best to learn how to make more complicated scripts through the Premiere Panels, but keep getting hung up at this one issue.

       

      I want to include checkboxes in the panel, that will allow an editor to "check" characteristics for their current project. They can then run the script from a button. Now I know this might not be the most compact or efficient way to code, but I am just copy/pasting a script with a few various changes for the project characteristics for the time being, and giving them different function names in the .jsx file (same set up that is shown in the Premiere.jsx file in the PProPanel sample). After adding some if statements to the HTML document javascript I call the function that I want to run, which works for a single function, but not when I add more than one. When multiple are involved I keep getting errors that "undefined is not a object" and that it is expecting a closing bracket. I have no clue where these are coming from.

       

      In the HTML javascript I have this (just a section of it):

       

      function myFunction() {

        if(document.getElementById("serialContent").checked == true){

        window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManage()", callback);

        }

        if(document.getElementById("serialContent").checked == false){

        window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManageAgain()", callback);

        }

        }

       

      and over in the .jsx I have this for an example:

       

      if (typeof($) == 'undefined') $ = {};

      $._MYFUNCTIONS = {

        mediaManage: function() {

        alert("success # 1");

        }

        mediaManageAgain: function() {

        alert(success # 2);

        }

      }

       

      Any ideas out there, it seems so simple?

        • 1. Re: Introducing multiple functions in Extendscript
          e.d. Level 3

          Hi,

           

          first off, I wonder if you actually HAVE a callback function?

          window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManage()", callback);
          

           

          otherwise it should only be

          window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManage()");
          

           

          That's what the error message suggests to me.

           

          Next thing, I have never used the calls to JSX functions the way you do.

          What I usually do is something like this:

          function myFunction() {
               var cs = new CSInterface();
               if(document.getElementById("serialContent").checked == true){
                    cs.evalScript("$._MYFUNCTIONS.mediaManage()", callback);
               } 
               if(document.getElementById("serialContent").checked == false){
                    cs.evalScript("$._MYFUNCTIONS.mediaManageAgain()", callback);
               } 
          }
          

           

          The CEP object is, if I remember correctly, reserved for methods that are part of the CEF, but not ExtendScript (which is in the .JSX).

          • 2. Re: Introducing multiple functions in Extendscript
            jportell25 Level 1

            I have not used the "new CSInterface()" function before, mostly because I am confused as to what it is. I have read the Cookbook but was still not sure of it. I am trying to mimic the code from the sample panels best I can to access the ExtendScript, which is what I really understand.

             

            I gave your idea a shot, and for some reason upon introducing the "Var cs = new CSInterface();" code, my HTML Javascript became unresponsive and will not check to see if the checkbox is checked. What is this doing in the background? Is there a reason it is disrupting the rest of the Javascript?

             

            I appreciate the response, just trying to wrap my head around this all.

            • 3. Re: Introducing multiple functions in Extendscript
              e.d. Level 3

              Hi,

               

              have you used Samples/PProPanel at master · Adobe-CEP/Samples · GitHub  as a reference before, or which one(s) have you been using?

              Okay, reading properly tells me this is your reference...

               

              In order to use CSInterface, you need to have files with the same functions to make it work...

              Short overview (as always, no guarantee re errors & omissions..) on the PPro Panel sample:

               

              manifest.xml -> must reference index.html and PProPanel.jsx

              index.html -> your panel, references ext.js and the .js files in the /lib/ subfolder

              PProPanel.jsx -> provides functions to access your .jsx files (evalFiles)

              ext.js -> "main script", uses PProPanel.jsx's functions to execute your .jsx files (line 217)

              /lib/CSInterface.js -> implements class CSInterface the methods of which drive CEP

               

              Which means you don't have to use CSInterface, it's (as the name says) an interface to CEP with more convenient methods.

              Of course, if you don't reference the relevant files, your script will not be executed.

               

               

              So you might as well stick with

              window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManage()");  
              

              because under the hood CSInterface does nothing else (see here).

               

              Have you tried this? Because my first question, if you have a callback function at all, seems still unanswered to me.

               

              Update:

              I did a quick check on my system. Funny enough, for me

              window.__adobe_cep__.evalScript("$._MYFUNCTIONS.mediaManage()"); 
              

               

              doesn't do anything, whereas

              var cs = new CSInterface();
              cs.evalScript("$._MYFUNCTIONS.mediaManage()"); 
              

               

              does work.

              Also with a cascade of conditions like you have mentioned.

              • 4. Re: Introducing multiple functions in Extendscript
                jportell25 Level 1

                Ah, Of course. I was not linking to the correct libraries in my HTML to get this to work. There is the issue for why CSInterface() was not working. However, now that that is back in working condition, I am still getting the same errors experienced in the original post -- "undefined is not an object" and "expected: }".

                 

                To answer your question, this is not a callback function, but the panel will need that capability in future iterations. I am working my way up, and with basing my code on the GitHub sample, using this set up was working for single function scripts.

                 

                I found a work around, but I don't know why this is allowing it to work. I have taken your advice in removing the "callback" portion, because your right, I have no reason to use this. Where before I had both my functions wrapped within "$._MYFUNCTIONS = {" like below:

                 

                $._MYFUNCTIONS = {

                  mediaManage: function() {

                  alert("success # 1");

                  }

                  mediaManageAgain: function() {

                  alert(success # 2);

                  }

                }

                 

                I instead wrapped each function in its own brackets and call, as so now:

                 

                $._MYFUNCTIONS = {

                  mediaManage: function() {

                  alert("success # 1");

                  }

                }

                $._MYFUNCTIONS1 = {

                  mediaManageAgain: function() {

                  alert("success # 2");

                  }

                }

                 

                Now when called in the HTML it runs fine. Any idea why this works and the other does not. I must be doing something incorrectly somewhere.

                • 5. Re: Introducing multiple functions in Extendscript
                  e.d. Level 3

                  Is this an exact copy&paste of your code?

                  If so, I think the problem is a missing comma (,) after the first mediaManage function declaration!

                   

                  $._MYFUNCTIONS = {

                    mediaManage: function() {

                    alert("success # 1");

                    }

                    mediaManageAgain: function() {

                    alert(success # 2);

                    }

                  }

                   

                  needs to be

                   

                  $._MYFUNCTIONS = {

                    mediaManage: function() {

                    alert("success # 1");

                    }, // comma goes here!

                    mediaManageAgain: function() {

                    alert(success # 2);

                    }

                  }

                  1 person found this helpful
                  • 6. Re: Introducing multiple functions in Extendscript
                    jportell25 Level 1

                    Thats it! Gahrr, so simple. I really appreciate all the help on this.