Getting started with Photoshop Panels in CS5

General Discussion of Scripting for Flex, Flash & CS SDK

Moderators: Tom, Kukurykus

myranalis

Getting started with Photoshop Panels in CS5

Post by myranalis »

I've downloaded a trial of the Flash builder 4 and I'm trying to work through the shortcut buttons tutorial here: http://www.adobe.com/devnet/photoshop/s ... cript.html ... cript.html. After a few tweaks to make the tut work in CS5 I've ended up with the mxml below which displays fine in a web browser, but has gives had Error #2302 in Photoshop CS5. Any suggestions as to what I've done wrong?

Also, I have had no luck figuring out the error logging in CS5 yet since the introductory notes in the document say the LocalConnectionTarget and SocketTarget components aren't available anymore.. So any pointers there??

Thanks

Anna

ShortcutButtons.mxml
Code: Select all<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" width="279" height="90" creationComplete="init()"
            >
   <fx:Declarations>

   </fx:Declarations>
   <fx:Script>
      <![CDATA[
      import com.adobe.csxs.core.CSXSInterface;
         import com.adobe.csxs.core.CSXSInterface;
         
         public var newDocTimer:Timer = new Timer(10000);
         public var closeDocTimer:Timer = new Timer(12000);

         
         public function callAddDocument():void{
            CSXSInterface.instance.evalScript("addDocument");
         }
         public function callCloseDocument():void{
            CSXSInterface.instance.evalScript("closeDocument");
         }
         
         public function init():void{
            CSXSInterface.instance.evalScript("PhotoshopPersistent");

            newDocTimer.addEventListener(TimerEvent.TIMER,newDocTimeHandler);
            closeDocTimer.addEventListener(TimerEvent.TIMER,closeDocTimeHandler);
            newDocTimer.start();
            closeDocTimer.start();
         }
         public function newDocTimeHandler(event:TimerEvent):void{
            if(actNewDoc.selected) callAddDocument();
         }
         public function closeDocTimeHandler(event:TimerEvent):void{
            if(actCloseDoc.selected) callCloseDocument();
         }

      ]]>
   </fx:Script>

   <s:CheckBox x="26" y="17" label="10 seconds" id="actNewDoc"/>
   <s:CheckBox x="26" y="43" label="12 seconds" id="actCloseDoc"/>
   <s:Button x="138" y="17" label="New Document" click="callAddDocument();" />
   <s:Button x="138" y="46" label="Close Document" click="callCloseDocument();" />

</s:Application>


ShortcutButtons.jsx
Code: Select allfunction addDocument(){
   app.documents.add();
}


function closeDocument(){
   app.activeDocument.close();
}
Mike Hale

Getting started with Photoshop Panels in CS5

Post by Mike Hale »

I still use Flex Builder 3 so this may not help but if I replace all your namespace declarations with xmlns:mx="http://www.adobe.com/2006/mxml" then replace all the ns shortcuts with mx it works for me in CS5. I don't think that I would use the panel sizes that you have in your code but everything works including the timers.

Code: Select all<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
             minWidth="955" minHeight="600" width="279" height="90" creationComplete="init()"
                >
       <mx:Script>
          <![CDATA[
          import com.adobe.csxs.core.CSXSInterface;
             import com.adobe.csxs.core.CSXSInterface;
             
             public var newDocTimer:Timer = new Timer(10000);
             public var closeDocTimer:Timer = new Timer(12000);

             
             public function callAddDocument():void{
                CSXSInterface.instance.evalScript("addDocument");
             }
             public function callCloseDocument():void{
                CSXSInterface.instance.evalScript("closeDocument");
             }
             
             public function init():void{
                CSXSInterface.instance.evalScript("PhotoshopPersistent");

                newDocTimer.addEventListener(TimerEvent.TIMER,newDocTimeHandler);
                closeDocTimer.addEventListener(TimerEvent.TIMER,closeDocTimeHandler);
                newDocTimer.start();
                closeDocTimer.start();
             }
             public function newDocTimeHandler(event:TimerEvent):void{
                if(actNewDoc.selected) callAddDocument();
             }
             public function closeDocTimeHandler(event:TimerEvent):void{
                if(actCloseDoc.selected) callCloseDocument();
             }

          ]]>
       </mx:Script>

       <mx:CheckBox x="26" y="17" label="10 seconds" id="actNewDoc"/>
       <mx:CheckBox x="26" y="43" label="12 seconds" id="actCloseDoc"/>
       <mx:Button x="138" y="17" label="New Document" click="callAddDocument();" />
       <mx:Button x="138" y="46" label="Close Document" click="callCloseDocument();" />

    </mx:Application>
myranalis

Getting started with Photoshop Panels in CS5

Post by myranalis »

Thanks Mike. I noticed, if I start my project with Flex 3.5 specified I get a namespace at least much more similar to yours. Haven't tried to walk through the tutorial yet with that setting - will do that

But shouldn't the Flex 4 in theory work too?? I don't know - I'm doing my head in trying to figure out how it all ties together and what is supposed to be compatible with each version of PS.
Mike Hale

Getting started with Photoshop Panels in CS5

Post by Mike Hale »

I'm not sure if Flex 4 will work with Photoshop. Flex Builder doesn't give me a choice, it uses 3.4. But for the CSXSLib I have a choice of 3.4 or 3.5. It would be my guess that Photoshop CS5 can't work with Flex 4. Up until shortly before it's release CS5 could run custom panels created for CS4 without change other than using the beta CSXSLib.

For error logging/debugging You can use a try/catch
Code: Select allcatch (errObject:Error) {
                 Alert.show(errObject.message +
                 " " + errObject.errorID.toString() +
                 " " + errObject.name);

Also, although I have not used it myself yet, some of the samples in the new Panel guide use a function named Logit which seems to create a progress/error log. See the sample ColorPicker.
myranalis

Getting started with Photoshop Panels in CS5

Post by myranalis »

Well, switching to 3.5 it works perfectly. So I guess that is the go for the moment at least

Another question though: All the samples I've looked at so far the swf seems to look for a javascript of the same name with the evalScript method. If I make the javascript file a jsxbin - it works IF i change the extension to jsx. Is there a way to explictly point it at a given javascript file? Or multiple javascript files for that matter?
Mike Hale

Getting started with Photoshop Panels in CS5

Post by Mike Hale »

As I understand it, no. It looks for a .jsx file with the same name as the panel. You can use include or evalScript statements in the main jsx to point to a different/multiple javascript files.