1 Reply Latest reply on Mar 24, 2011 12:40 PM by DBarranca

    PSEvents via ExternalInterface

    DBarranca Level 4

      Hello,

      I'm trying to add in Photoshop Extended an Event listener for Count Tools items, so each time the user adds one, something should happen. Alas, it doesn't.

       

      In Extension Builder I've added the CSHA lib.

      PSEvents are not well documented in the reference, imho, compared to AI events for instance, where there's at least a line of explanation. Anyway, there's no mention of counters, nor in the Photoshop Event Codes table.

      As CS SDK Help suggests (Photoshop Guide page, in the Product-specific Guide), I have to use ExternalInterface; ScriptingListener code for Count adding is as follows:

       

      // =======================================================
      var idcountAdd = stringIDToTypeID( "countAdd" );
          var desc4 = new ActionDescriptor();
          var idX = charIDToTypeID( "X   " );
          desc4.putDouble( idX, 1917.500000 );
          var idY = charIDToTypeID( "Y   " );
          desc4.putDouble( idY, 413.500000 );
      executeAction( idcountAdd, desc4, DialogModes.NO );
      // =======================================================
      

       

      So in the mxml I've added:

       

      private const COUNTER:int = Photoshop.app.stringIDToTypeID( "countAdd" );
      
      private function onCreationComplete():void
      {
           model = AppModel.getInstance();
           CSXSInterface.instance.evalScript("PhotoshopRegisterEvent", COUNTER);
           ExternalInterface.addCallback("PhotoshopCallback" + CSXSInterface.getInstance().getExtensionId(), myPhotoshopCallback)
      }
      
      private function myPhotoshopCallback(eventID:Number, descID:Number):void
      {
           var desc:ActionDescriptor = new ActionDescriptor();
           desc.fromID(descID);
           switch (eventID)
           {
                case COUNTER:
                     trace("Counter added")
                     break;
           }
      }
      
      

       

      And it doesn't work at all. Moreover, I keep getting "PSHostAdapter not found in the Adobe Photoshop CS5 plugins. It may not be available for the Host Adapter libraries." error from Flash Builder.

      What's wrong?!

      Any help is really appreciated!

      Thanks in advance

       

      Davide Barranca

        • 1. Re: PSEvents via ExternalInterface
          DBarranca Level 4

          Listening for two events instead of only one make it work:

           

          private const COUNTER:int = Photoshop.app.stringIDToTypeID( "countAdd" );
          private const COPY_INT:int  = Photoshop.app.charIDToTypeID('copy');
          
          private function onCreationComplete():void
          {
               model = AppModel.getInstance();
               CSXSInterface.instance.evalScript("PhotoshopRegisterEvent", COPY_INT + "," + COUNTER);
               ExternalInterface.addCallback("PhotoshopCallback" + CSXSInterface.getInstance().getExtensionId(), myPhotoshopCallback)
          }
          
          private function myPhotoshopCallback(eventID:Number, descID:Number):void
          {
               var desc:ActionDescriptor = new ActionDescriptor();    // these two lines are useless here
               desc.fromID(descID);                                   //
               switch (eventID)
               {
                    case COUNTER:
                    trace("Counter fired")
                    break;
                 case COPY_INT:
                    trace("Copy fired");
                    break;     
                }
          }
          
          

           

           

          After some extra research, I've understood that the second parameter for the addCallback should be a string, and adding the "," made it. So more properly I've added a .toString()

           

          I still have to understand how to remove the listener. It's straightforward with PSHA with .removeEventListener(), but now with ExternalInterface?

          I've also searched for documentation about "PhotoshopRegisterEvent", but I couldn't find anything useful. Where does it comes from, it's kind of a standard function? How can I find whether other similar (and possibly useful) functions exist - perhaps a "PhotoshopUnRegisterEvent" ? :-)

          Too many questions...

          Regards

           

           

           

          Davide