11 Replies Latest reply on Sep 12, 2011 2:33 PM by Pierre-RAFFA

    same jsxInterface for my two palettes

    Pierre-RAFFA Level 1

      Hi all,

       

      When i create a jsxInterface by using _jsxInterface = HostObject.getRoot(HostObject.extensions[0]) but i get same jsxInterface in my two palettes. It's a problem. So I decided to loop on all extensions like that.

       

      var vResult:SyncRequestResult = CSXSInterface.instance.getExtensions();
                  var vArray:ArrayCollection = null;
                  if((SyncRequestResult.COMPLETE == vResult.status) && vResult.data)
                  {
                      vArray = vResult.data as ArrayCollection;
                     
                      for each(var vExtension:Extension in vArray )
                      {
                          if ( vExtension.id == inExtensionId )
                          {
                              _jsxInterface = HostObject.getRoot(vExtension.id);
                              _jsxInterface.eval(vScripts);
                              _jsxInterface.setJSXController(this);
                          }
                      }
                  }

       

      But jsxInterface is now null.....

      Is there any solution ?

       

      Thanks.

      Regards.

        • 1. Re: same jsxInterface for my two palettes
          Bob Stucky Adobe Employee

          I would think you could solve your problem simply by changing your jsx.

           

          var palette1 = {};

          palette1.asInterface;

           

          palette1.setInterface( obj ) {

               palette1.asInterface = obj

          }

           

          Do the same for palette2, both jsx's should load without squashing each other. Seems to me it *should* work. But I haven't tested it...

           

          Regards

           

          Bob

          • 2. Re: same jsxInterface for my two palettes
            Pierre-RAFFA Level 1

            I don't understand this way ...

            It's not really jsx load which causes problem but this line ( _jsxInterface.eval(vScripts) of palette2 ) which deletes all scripts of palette1.

            • 3. Re: same jsxInterface for my two palettes
              Harbs. Adobe Community Professional & MVP

              I'm not sure what happened. This post was on the CS SDK forum which I respinded to, but it seemed to have disappeared from there.

               

              Here's what I wrote:

               

              Interesting.

               

              I never realized (or thought about) that the functions are shared by extensions.

               

              It makes 100% sense, because the JS is eval()ed in the STAGEMANAGER0 scripting engine (in InDesign) which the stage manager, and by extension, all extensions use. Open up ESTK, and you'll see all functions created in HostObject.

               

              So, unless we're given some way to pick the scripting engine in CS SDK (please!!!), I think your heading up a dead end.

               

              You can prefix all your functions with a prefix or encapsulate them in an object to prevent clashes... (which is what Bob suggested)

               

              HTH,
              Harbs

              • 4. Re: same jsxInterface for my two palettes
                Harbs. Adobe Community Professional & MVP

                I'm moving this discussion to the CS SDK forum...

                • 5. Re: same jsxInterface for my two palettes
                  Harbs. Adobe Community Professional & MVP

                  Pierre-RAFFA wrote:

                   

                  I don't understand this way ...

                  It's not really jsx load which causes problem but this line ( _jsxInterface.eval(vScripts) of palette2 ) which deletes all scripts of palette1.

                  Open ESTK and check out the engine names and function names within each engine. What do you see?

                  • 6. Re: same jsxInterface for my two palettes
                    Bob Stucky Adobe Employee

                    That is exactly the point.

                     

                    You're using a single ExtendScript global context. So if script1 of palette1 contains a function:

                     

                    var asInterface;

                    setAsInterface = function( object ) {

                          asInterface = object;

                    }

                     

                    And script2 of palette2 contains a function

                     

                    var asInterface;

                    setAsInterface  = function( object ) {

                          asInterface = object;

                    }

                     

                    Then loading script2 of palette2 overwrites script1 of palette1.

                     

                    But if script1:

                     

                    var script1 = {};

                    script1.asInterface;

                    script1.setAsInterface = function( object ) {

                          script1.asInterface = object;

                    }

                     

                    and script2:

                     

                    var script2 = {};

                    script2.asInterface;

                    script2.setAsInterface = function( object ) {

                          script2.asInterface = object;

                    }

                     

                    They don't overwrite each other.

                     

                    Oviously, if you want to call back to palette2, you'd need to use:

                     

                    script2.asInterface.palette2Method();

                     

                    Interestingly, you actually should be able to call pallette1 from from palette2 so long as both palettes are loaded...

                     

                    script2.doSomething = function() { // this script is called from jsxInterface in palette2

                         script1.asInterface.palette1Method(); // this should call into palette1...

                    }

                     

                    Inter-extension communication is better handled by CSXSEvents, though.

                     

                    Bob

                    • 7. Re: same jsxInterface for my two palettes
                      Harbs. Adobe Community Professional & MVP

                      Bob,

                       

                      What you wrote is what I'd expect.

                       

                      He wrote that the second one deletes the first one (not overwrites it). I'm guessing that he was not precise in his wording, but I'm wondering if somehow it might spawn a second scripting engine?

                       

                      Harbs

                      • 8. Re: same jsxInterface for my two palettes
                        Bob Stucky Adobe Employee

                        Like I said, I haven't tried it; but, I would be very surprised it didn't work.

                        • 9. Re: same jsxInterface for my two palettes
                          Pierre-RAFFA Level 1

                          In fact, the first time I use _jsxInterface.eval(vScripts) on palette1, all works. And after palette2 opens, palette1 doesn't work because scripts has been overwritten by another _jsxInterface.eval(vScripts)

                          • 10. Re: same jsxInterface for my two palettes
                            Harbs. Adobe Community Professional & MVP

                            What do you mean by "overwritten"? That it launches function 2 instead of function 1?

                            • 11. Re: same jsxInterface for my two palettes
                              Pierre-RAFFA Level 1

                              I will test again tomorrow ... I m at home