The Photoshop connection class sets up encryption and handles socket transmission of data and messages to and from Photoshop.
The first step is to make a connection to Photoshop using connect(), and then initialize the encryption. You can do this by deriving a new key
based on a password, using initEncryption(), or by using initEncryptionFromKey() and passing in a pre-derived key. This is convenient for mobile devices,
as deriving the key anew is a costly process (~3 seconds), and will block your UI from updating during the derivation process. The best way to do this is
to call initEncryption() once, then call getKey() and save it somewhere. You can provide that key in initEncryptionFromKey(), but note that your requests to Photoshop
will fail if the key is out of date (usually if the password changed).
After successfully connecting and initializing encryption, you may send data to Photoshop, and receive results. There are a few classes that make this process easier.
Look into the MessageDispatcher and SubscriptionManager classes, and read the documentation. You can also create Messages yourself using the official Photoshop SDK documentation,
and simply call encryptAndSendData() in this class, if you want lower-level control.
The SubscriptionManager that this connection should use when determining if a response is tied to a subscription.
This must be set to the SubscriptionManager that you've attached your event listeners to.
Constructor Detail
PhotoshopConnection
()
Constructor
public function PhotoshopConnection()
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Constructor. Creates a new Photoshop connection. No connection is attempted in this function, nor is the encryption set up.
Use the connect() and initEncryption() classes for these tasks.
Method Detail
connect
()
method
public function connect(serverName:String, serverPort:int = 49494):void
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Opens a Photoshop data connection to Photoshop. You may call this function before you call initEncryption(),
but you will have to initialize the encryption before you can successfully communicate with Photoshop.
Parameters
serverName:String — IP address or resolvable hostname of the server
serverPort:int (default = 49494) — Port to connect to. Default is 49494
disconnect
()
method
public function disconnect():void
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Disconnects the connection to Photoshop
encryptAndSendData
()
method
public function encryptAndSendData(data:ByteArray):Boolean
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Will both encrypt and send data to Photoshop. However, it doesn't ensure that your data is properly formatted.
If you're interested in creating and dispatching properly formatted messages, look into the MessageDispatcher class.
Parameters
data:ByteArray — The payload to encrypt and send
Returns
Boolean — Returns true or false based on whether the operations were successful
encryptData
()
method
public function encryptData(data:ByteArray):Boolean
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Encrypts data such that Photoshop will be able to decrypt it. This won't ensure that your data is properly formatted, however.
If you're interested in creating and dispatching properly formatted messages, look into the MessageDispatcher class.
This function requires that the developer has already initialized the encryption.
Parameters
data:ByteArray — The data to encrypt
Returns
Boolean — Returns true or false based on whether the operations were successful
getKey
()
method
public function getKey():String
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Returns the derived key. This is handy if you want to save the key and provide the next time your application
connects to Photoshop...this will bypass the costly key derivation subroutines inside of initEncryption().
See also initializeEncryptionFromKey();
Returns
String — The derived key. Null if you haven't yet successfully called initEncryption()
initEncryption
()
method
public function initEncryption(password:String = PhotoshopSDK):void
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Derives the key necessary for all communication with Photoshop. This is a costly function. However, it must be called
before communication can be successful. It's recommended that you inform the user that initializing enryption will take some time before
calling this function.
Parameters
password:String (default = PhotoshopSDK) — The pre-shared password between Photoshop and your client.
initEncryptionFromKey
()
method
public function initEncryptionFromKey(key:String):void
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Initializes encryption using a key that you provide. Useful if you want to store the key and speed up the
encryption process. You may call this function and then proceed to make calls to Photoshop without having to call
initEncryption().
If you provide an incorrect key, you'll only know after your first attempt to communicate with Photoshop.
If you store a key value and the user changes his or her password, your saved key will be invalid!
Parameters
key:String — The key you wish to use for encryption. Most easily obtained by calling initEncryption(), and then calling getKey() and saving it.
sendDatagram
()
method
public function sendDatagram(data:ByteArray):Boolean
Language Version :
ActionScript 3.0
Runtime Versions :
AIR 1.0, Flash Player 10
Sends raw data to Photoshop, without encrypting it or wrapping it in a properly formatted message.
If you want to generate your own message and dispatch it, look at the MessageDispatcher class.
If you want to encrypt your data before pushing it to Photoshop, you'll want to use encryptAndSendData(), or encryptData()
Parameters
data:ByteArray — The payload of data
Returns
Boolean — Returns false if the operation failed immediately.