ColorPicker.jsx

Summary

The script contains four functions to retrieve and set the background and foreground color. There are also two utility functions where one converts a color value retrieved from the Flash panel to RGB values and the other converts to XML so that the SWF file and the CSXS Library can parse and use prooperly. This script is to be used by a SWF file called ColorPicker.swf created though Adobe Flex.

Author: John Huan Vu, Photoshop Engineering Intern, Adobe Systems Incorporated


Method Summary
static String convertToXML(<String> property, <String> identifier)
           In order to communicate to the SWF file, it must be written as an XML containing the property and identifier.
static String getBackground()
           Get the background color on Photoshop.
static String getForeground()
           Get the foreground color on Photoshop.
static void setBackground(<Integer> color)
           Sets the background color on Photoshop.
static void setForeground(<Integer> color)
           Sets the foreground color on Photoshop.
static SolidColor translateColor(<Integer> c)
           Take the integer value corresponding to a color and parse the values for red, green, and blue to SolidColor.

/**************************************************************************
	ADOBE SYSTEMS INCORPORATED
	 Copyright 2008 Adobe Systems Incorporated
	 All Rights Reserved.

	NOTICE:  Adobe permits you to use, modify, and distribute this file
	in accordance with the terms of the Adobe license agreement accompanying
	it.  If you have received this file from a source other than Adobe, then
	your use, modification, or distribution of it requires the prior written
	permission of Adobe.
**************************************************************************/

/**  Filename: ColorPicker.jsx
	@author John Huan Vu, Photoshop Engineering Intern, Adobe Systems Incorporated
	@fileoverview The script contains four functions to retrieve and set
			the background and foreground color. There are also
			two utility functions where one converts a color value
			retrieved from the Flash panel to RGB values and the
			other converts to XML so that the SWF file and the
			CSXS Library can parse and use prooperly. This script
			is to be used by a SWF file called ColorPicker.swf
			created though Adobe Flex.
*/

/**
	Sets the foreground color on Photoshop.
	@param {Integer} color An integer value that's ready to be parsed for RGB values.
*/
function setForeground(color){
	app.foregroundColor = translateColor(color);
}


/**
	Get the foreground color on Photoshop.
	@returns An XML object containing the hex value of the foreground color.
	@type String
*/
function getForeground(){
	xml = "<object>";
	xml += convertToXML(app.foregroundColor.rgb.hexValue.toString(), "foreground");
	xml += "</object>"
	return xml;
}


/**
	Sets the background color on Photoshop.
	@param {Integer} color An integer value that's ready to be parsed for RGB values.
*/
function setBackground(color){
	app.backgroundColor = translateColor(color);
}


/**
	Get the background color on Photoshop.
	@returns An XML object containing the hex value of the foreground color.
	@type String
*/
function getBackground(){
	xml = "<object>";
	xml += convertToXML(app.backgroundColor.rgb.hexValue.toString(), "background");
	xml += "</object>"
	return xml;
}


/**
	Take the integer value corresponding to a color and parse the values for
	red, green, and blue to SolidColor.
	@param {Integer} c An integer value that's ready to be parsed for RGB values.
	@returns The type SolidColor with red, green, and blue values parsed from "c".
	@type SolidColor
*/
function translateColor(c){
	var color = new SolidColor;
	color.rgb.red 	= (c >> 16) & 0xFF;
	color.rgb.green = (c >> 8) & 0xFF;
	color.rgb.blue 	= c & 0xFF;
	return color;
}


/**
	In order to communicate to the SWF file, it must be written as an XML
		containing the property and identifier. This utility is very helpful for
		a two-way communication between the JSX and SWF.
	@param {String} property The property or value for the identifier
	@param {String} identifier The unique identifier for the property
	@returns An xml containing the property and identifier
	@type String
*/
function convertToXML(property, identifier){
	var type = typeof property;
	var xml = '<property id = "' + identifier + '" >';
	
	switch(type){
		case "number":
			xml += "<number>";
			xml += property.toString();
			xml += "</number>";
			break;
		case "boolean":
			xml += "<" + property.toString() + "/>";
			break;
		case "string":
			xml += "<string>";
			xml += property.toString();
			xml += "</string>";
			break;
		case "object":
			// Object case is currently not supported
			alert("Object case is currently not supported");
			//xml += "<object>";
			//for(var i in property)
			//	xml += convertToXML(property[i], 
			//xml += "</object>";
			break;
		case "undefined":
			xml += "<string>undefined</string>";
			break;
		default:
			alert("Type " + type + " is unknown.");
			return "";
	}
	xml += '</property>';
	return xml;
}


Documentation generated by JSDoc on Wed Sep 3 16:09:11 2008