Packagecom.adobe.photoshop.connection
Classpublic class PhotoshopConnection
InheritancePhotoshopConnection Inheritance flash.events.EventDispatcher

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

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.



Public Properties
 PropertyDefined By
  subscriptionManager : SubscriptionManager
The SubscriptionManager that this connection should use when determining if a response is tied to a subscription.
PhotoshopConnection
Public Methods
 MethodDefined By
  
Constructor.
PhotoshopConnection
  
connect(serverName:String, serverPort:int = 49494):void
Opens a Photoshop data connection to Photoshop.
PhotoshopConnection
  
disconnect():void
Disconnects the connection to Photoshop
PhotoshopConnection
  
encryptAndSendData(data:ByteArray):Boolean
Will both encrypt and send data to Photoshop.
PhotoshopConnection
  
encryptData(data:ByteArray):Boolean
Encrypts data such that Photoshop will be able to decrypt it.
PhotoshopConnection
  
getKey():String
Returns the derived key.
PhotoshopConnection
  
initEncryption(password:String = PhotoshopSDK):void
Derives the key necessary for all communication with Photoshop.
PhotoshopConnection
  
initEncryptionFromKey(key:String):void
Initializes encryption using a key that you provide.
PhotoshopConnection
  
sendDatagram(data:ByteArray):Boolean
Sends raw data to Photoshop, without encrypting it or wrapping it in a properly formatted message.
PhotoshopConnection
Events
 Event Summary Defined By
  Dispatched when the connection to Photoshop has been establishedPhotoshopConnection
  Dispatched when the connection is terminatedPhotoshopConnection
  Dispatched should encryption or key derivation fail (or if initializing encryption from a provided key fails)PhotoshopConnection
  Dispatched when the key has been encrypted, and the connection is ready to send and receive data.PhotoshopConnection
  Dispatched when there's been an error in either data transfer, encryption, or connection management.PhotoshopConnection
  Dispatched when an error message is received from Photoshop.PhotoshopConnection
  Dispatched when the connection has received an imagePhotoshopConnection
  Dispatched when a message is received from Photoshop.PhotoshopConnection
  Dispatched when a message is sent to Photoshop.PhotoshopConnection
  Dispatched when there is progress in parsing a response or sending a message.PhotoshopConnection
Public Constants
 ConstantDefined By
  PHOTOSHOP_CONNECTION_API_VERSION : int = 1
[static] The Photoshop API version that this code supports
PhotoshopConnection
Property Detail
subscriptionManagerproperty
public var subscriptionManager:SubscriptionManager

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.
Event Detail
ConnectedEvent Event
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.CONNECTED

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when the connection to Photoshop has been established

ConnectedEvent is dispatched after a connection was successfully established
DisconnectedEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.DISCONNECTED

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when the connection is terminated

Upon disconnection of a service or connection, a DisconnectedEvent PhotoshopEvent will be dispatched.
EncryptionFailedEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.ENCRYPTION_FAILED

Language Version : ActionScript 3.0

Dispatched should encryption or key derivation fail (or if initializing encryption from a provided key fails)

Dispatched if encryption or key derivation should fail
encryptionSuccess Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.ENCRYPTION_SUCCESS

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when the key has been encrypted, and the connection is ready to send and receive data.

Dispatched after encryption has been successfully initialized
ErrorEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.ERROR

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when there's been an error in either data transfer, encryption, or connection management.

ErrorEvent is dispatched in the case of an error. The data property will contain additional information regarding the error
ErrorMessageReceivedEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopMessageEvent
PhotoshopMessageEvent.type property = com.adobe.photoshop.events.PhotoshopMessageEvent.ERROR_MESSAGE_RECEIVED

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when an error message is received from Photoshop.

Dispatched when a Message has been received, but it contains information indicating that there's been an error
ImageReceivedEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.IMAGE_RECEIVED

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when the connection has received an image

MessageReceivedEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopMessageEvent
PhotoshopMessageEvent.type property = com.adobe.photoshop.events.PhotoshopMessageEvent.MESSAGE_RECEIVED

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when a message is received from Photoshop.

A MessageReceivedEvent is dispatched when a service or connection has received an IMessage.
MessageSentEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopMessageEvent
PhotoshopMessageEvent.type property = com.adobe.photoshop.events.PhotoshopMessageEvent.MESSAGE_SENT

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when a message is sent to Photoshop.

A PhotoshopMessageEvent with the MessageSentEvent is dispatched when a message has been successfully sent
ProgressEvent Event  
Event Object Type: com.adobe.photoshop.events.PhotoshopEvent
PhotoshopEvent.type property = com.adobe.photoshop.events.PhotoshopEvent.PROGRESS

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10

Dispatched when there is progress in parsing a response or sending a message. Useful for large transfers.

ProgressEvent is dispatched when there has been progress made in sending, receiving, or parsing messages.
Constant Detail
PHOTOSHOP_CONNECTION_API_VERSIONConstant
public static const PHOTOSHOP_CONNECTION_API_VERSION:int = 1

The Photoshop API version that this code supports