Packagecom.adobe.photoshop.dispatchers
Classpublic class MessageDispatcher
InheritanceMessageDispatcher Inheritance Object

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

The MessageDispatcher is an abstraction layer on top of the PhotoshopConnection, which makes it easy to send properly formatted messages to Photoshop. You can either call some of the helper functions that will create and dispatch the messages for you (createNewDocument, requestThumbnail, etc.), or create your own IMessage and call sendMessage(). Refer to the Photoshop scripting documentation to see the format of the messages you should send.



Public Methods
 MethodDefined By
  
Constructor.
MessageDispatcher
  
createNewDocument(transactionID:int = -1, width:int = 640, height:int = 480, ppi:int = 72):void
Dispatches a message instructing Photoshop to create a new document with the specified parameters.
MessageDispatcher
  
generateTextMessage(text:String, transactionID:int = -1):TextMessage
[static] Creates a TextMessage, given a String and an optional transactionID.
MessageDispatcher
  
[static] Generates a TextMessage that can be sent to Photoshop, which will instruct photoshop to either subscribe or unsubscribe from the given Subscription.
MessageDispatcher
  
getTool(transactionID:int = -1):void
Instructs Photoshop to respond and tell us what tool is currently selected.
MessageDispatcher
  
requestThumbnail(transactionID:int = -1, width:int = 640, height:int = 480, format:int = 1):void
Dispatches a message requesting that Photoshop return an image of the currently opened document.
MessageDispatcher
  
sendMessage(message:IMessage):void
Takes an IMessage and sends it to Photoshop.
MessageDispatcher
  
setTool(transactionID:int = -1, toolType:String = paintbrushTool):void
Dispatches a message instructing Photoshop to set the current tool to the toolType.
MessageDispatcher
Protected Constants
 ConstantDefined By
  MESSAGE_TEXT_ACTIVEVIEW_CHANGED : String
[static] Update us when the active view changes
MessageDispatcher
  MESSAGE_TEXT_BRUSH_SIZE_SET : String
[static]
MessageDispatcher
  MESSAGE_TEXT_COLOR_BACKGROUND : String
[static] Instructs Photoshop to either subscribe or unsubcribe from background color changes
MessageDispatcher
  MESSAGE_TEXT_COLOR_FOREGROUND : String
[static] Instructs Photoshop to either subscribe or unsubscribe from foreground color changes
MessageDispatcher
  MESSAGE_TEXT_COLOR_SETTINGS_CHANGED : String
[static] Update us when the color settings change
MessageDispatcher
  MESSAGE_TEXT_CURRENTDOCUMENT_CHANGED : String
[static] Update us when the current document changes
MessageDispatcher
  MESSAGE_TEXT_DOCUMENT_CHANGED : String
[static] Update us when a document is changed
MessageDispatcher
  MESSAGE_TEXT_DOCUMENT_CLOSED : String
[static] Update us when a document is closed
MessageDispatcher
  MESSAGE_TEXT_DOCUMENTS_ADD : String = documents.add($1, $2, $3)
[static] Creates a new document
MessageDispatcher
  MESSAGE_TEXT_DOCUMENTS_SEND_THUMBNAIL : String
[static] Requests that Photoshop send us a JPG of the current document
MessageDispatcher
  MESSAGE_TEXT_DOCUMENTVIEW_CREATED : String
[static] Update us when a new DocumentView is created
MessageDispatcher
  MESSAGE_TEXT_KEYBOARD_SHORTCUTS_CHANGED : String
[static] Update us when the keyboard shortcuts change
MessageDispatcher
  MESSAGE_TEXT_PREFERENCES_CHANGED : String
[static] Update us when the preferences change
MessageDispatcher
  MESSAGE_TEXT_QUICK_MASK_STATE_CHANGED : String
[static] Update us when the quick mask state changes
MessageDispatcher
  MESSAGE_TEXT_SCREEN_MODE_CHANGED : String
[static] Update us when the screen mode changes
MessageDispatcher
  MESSAGE_TEXT_TOOL_CHANGED : String
[static] Update us when the selected tool changes
MessageDispatcher
  MESSAGE_TEXT_TOOLS_SET : String
[static] Tells Photoshop to select a tool
MessageDispatcher
  MESSAGE_TEXT_TOOLS_WHICH : String
[static] Asks Photoshop to tell us what tool is currently selected
MessageDispatcher
Constructor Detail
MessageDispatcher()Constructor
public function MessageDispatcher(pc:PhotoshopConnection)

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

Constructor. Creates a new MessageDispatcher.

Parameters
pc:PhotoshopConnection — The PhotoshopConnection to use when sending out messages
Method Detail
createNewDocument()method
public function createNewDocument(transactionID:int = -1, width:int = 640, height:int = 480, ppi:int = 72):void

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

Dispatches a message instructing Photoshop to create a new document with the specified parameters.

Parameters

transactionID:int (default = -1) — You can override the default value if you wish to send the message with a custom transactionID. If you leave it as -1, the message dispatcher will keep track of transactionIDs for you. It's recommended that you don't mix these two systems, as it might lead to conflicts and unpredictable behavior.
 
width:int (default = 640) — The width of the document to create, in pixels
 
height:int (default = 480) — The height of the document to create, in pixels
 
ppi:int (default = 72) — The density of the document to create, in pixels per inch

generateTextMessage()method 
public static function generateTextMessage(text:String, transactionID:int = -1):TextMessage

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

Creates a TextMessage, given a String and an optional transactionID.

Parameters

text:String — The payload of the TextMessage to be created
 
transactionID:int (default = -1) — You can override the default value if you wish to send the message with a custom transactionID. If you leave it as -1, the message dispatcher will keep track of transactionIDs for you. It's recommended that you don't mix these two systems, as it might lead to conflicts and unpredictable behavior.

Returns
TextMessage — The generated TextMessage
generateTextMessageForSubscribingOrUnsubscribing()method 
public static function generateTextMessageForSubscribingOrUnsubscribing(subscription:Subscription, subscribe:Boolean = true):TextMessage

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

Generates a TextMessage that can be sent to Photoshop, which will instruct photoshop to either subscribe or unsubscribe from the given Subscription. This function looks at the Subscription.subscriptionType to determine the exact Photoshop command that should be placed in the TextMessage. This function is used by the SubscriptionManager, and it's likely that you don't want to call it yourself. However, this function may be useful if you're creating your own Subscription pattern. If that's the case, also look at the code/comments for the Subscription, SubscriptionEvent, and SubscriptionManager.

Parameters

subscription:Subscription — The Subscription that should be subscribed to or unsubscribed from
 
subscribe:Boolean (default = true) — A boolean. If true, the TextMessage will contain a command that tells Photoshop to susbcribe. If false, it contains an unsubscribe command.

Returns
TextMessage — A TextMessage containing the command for Photoshop
getTool()method 
public function getTool(transactionID:int = -1):void

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

Instructs Photoshop to respond and tell us what tool is currently selected.

Parameters

transactionID:int (default = -1) — You can override the default value if you wish to send the message with a custom transactionID. If you leave it as -1, the message dispatcher will keep track of transactionIDs for you. It's recommended that you don't mix these two systems, as it might lead to conflicts and unpredictable behavior.

requestThumbnail()method 
public function requestThumbnail(transactionID:int = -1, width:int = 640, height:int = 480, format:int = 1):void

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

Dispatches a message requesting that Photoshop return an image of the currently opened document.

Parameters

transactionID:int (default = -1) — You can override the default value if you wish to send the message with a custom transactionID. If you leave it as -1, the message dispatcher will keep track of transactionIDs for you. It's recommended that you don't mix these two systems, as it might lead to conflicts and unpredictable behavior.
 
width:int (default = 640) — The width of the returned image, in pixels
 
height:int (default = 480) — The height of the returned image, in pixels
 
format:int (default = 1) — The format of the returned image, according to the Photoshop API. Leaving this as 1 will return a JPG. Passing in other values may have unintended effects, or require that you parse the returned image yourself.

sendMessage()method 
public function sendMessage(message:IMessage):void

Takes an IMessage and sends it to Photoshop. The amount of time this function blocks will vary, depending on the type of message, and its size. It will send the data in an asynchronous manner, but some requisite steps, such as converting a Bitmap to a JPG, may take a short amount of time.

Parameters

message:IMessage — The IMessage Object to send to Photoshop

setTool()method 
public function setTool(transactionID:int = -1, toolType:String = paintbrushTool):void

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

Dispatches a message instructing Photoshop to set the current tool to the toolType. See com.adobe.photoshop.tools.Tool for a list of toolTypes.

Parameters

transactionID:int (default = -1) — You can override the default value if you wish to send the message with a custom transactionID. If you leave it as -1, the message dispatcher will keep track of transactionIDs for you. It's recommended that you don't mix these two systems, as it might lead to conflicts and unpredictable behavior.
 
toolType:String (default = paintbrushTool) — A String representation that specifies the type of tool you want selected. See the Tool class.

Constant Detail
MESSAGE_TEXT_ACTIVEVIEW_CHANGEDConstant
protected static const MESSAGE_TEXT_ACTIVEVIEW_CHANGED:String

Update us when the active view changes

MESSAGE_TEXT_BRUSH_SIZE_SETConstant 
protected static const MESSAGE_TEXT_BRUSH_SIZE_SET:String

MESSAGE_TEXT_COLOR_BACKGROUNDConstant 
protected static const MESSAGE_TEXT_COLOR_BACKGROUND:String

Instructs Photoshop to either subscribe or unsubcribe from background color changes

MESSAGE_TEXT_COLOR_FOREGROUNDConstant 
protected static const MESSAGE_TEXT_COLOR_FOREGROUND:String

Instructs Photoshop to either subscribe or unsubscribe from foreground color changes

MESSAGE_TEXT_COLOR_SETTINGS_CHANGEDConstant 
protected static const MESSAGE_TEXT_COLOR_SETTINGS_CHANGED:String

Update us when the color settings change

MESSAGE_TEXT_CURRENTDOCUMENT_CHANGEDConstant 
protected static const MESSAGE_TEXT_CURRENTDOCUMENT_CHANGED:String

Update us when the current document changes

MESSAGE_TEXT_DOCUMENT_CHANGEDConstant 
protected static const MESSAGE_TEXT_DOCUMENT_CHANGED:String

Update us when a document is changed

MESSAGE_TEXT_DOCUMENT_CLOSEDConstant 
protected static const MESSAGE_TEXT_DOCUMENT_CLOSED:String

Update us when a document is closed

MESSAGE_TEXT_DOCUMENTS_ADDConstant 
protected static const MESSAGE_TEXT_DOCUMENTS_ADD:String = documents.add($1, $2, $3)

Creates a new document

MESSAGE_TEXT_DOCUMENTS_SEND_THUMBNAILConstant 
protected static const MESSAGE_TEXT_DOCUMENTS_SEND_THUMBNAIL:String

Requests that Photoshop send us a JPG of the current document

MESSAGE_TEXT_DOCUMENTVIEW_CREATEDConstant 
protected static const MESSAGE_TEXT_DOCUMENTVIEW_CREATED:String

Update us when a new DocumentView is created

MESSAGE_TEXT_KEYBOARD_SHORTCUTS_CHANGEDConstant 
protected static const MESSAGE_TEXT_KEYBOARD_SHORTCUTS_CHANGED:String

Update us when the keyboard shortcuts change

MESSAGE_TEXT_PREFERENCES_CHANGEDConstant 
protected static const MESSAGE_TEXT_PREFERENCES_CHANGED:String

Update us when the preferences change

MESSAGE_TEXT_QUICK_MASK_STATE_CHANGEDConstant 
protected static const MESSAGE_TEXT_QUICK_MASK_STATE_CHANGED:String

Update us when the quick mask state changes

MESSAGE_TEXT_SCREEN_MODE_CHANGEDConstant 
protected static const MESSAGE_TEXT_SCREEN_MODE_CHANGED:String

Update us when the screen mode changes

MESSAGE_TEXT_TOOL_CHANGEDConstant 
protected static const MESSAGE_TEXT_TOOL_CHANGED:String

Update us when the selected tool changes

MESSAGE_TEXT_TOOLS_SETConstant 
protected static const MESSAGE_TEXT_TOOLS_SET:String

Tells Photoshop to select a tool

MESSAGE_TEXT_TOOLS_WHICHConstant 
protected static const MESSAGE_TEXT_TOOLS_WHICH:String

Asks Photoshop to tell us what tool is currently selected