Return to Snippet

Revision: 23523
at February 8, 2010 20:29 by mhulse


Initial Code
/**
* Color (AS3), version 1.0
*
* Enter description here
*
* <pre>
*  ____                   _      ____
* |  __| _ __ ___    ___ | | __ |__  |
* | |   | '_ ` _ \  / __|| |/ /    | |
* | |   | | | | | || (__ |   <     | |
* | |__ |_| |_| |_| \___||_|\_\  __| |
* |____|                        |____|
*
* </pre>
*
* @class  	: 	Color
* @author 	:  	Matthijs C. Kamstra [mck]
* @version :	1.0 - class creation (AS3)
* @since 	:	11-5-2008 0:22
*
*/
package nl.matthijskamstra.utils {

	import flash.display.*;
	import flash.events.*;
	import flash.geom.ColorTransform;

	public class Color {

		// Constants:
		public static var CLASS_REF = nl.matthijskamstra.utils.Color;
		public static var CLASS_NAME : String = "Color";
		public static var LINKAGE_ID : String = "nl.matthijskamstra.utils.Color";	

		/**
		* Constructor
		*
		* @usage   	import nl.matthijskamstra.utils.Color; // import
		*			var __Color:Color = new Color ( this );
		* @param	$targetObj		a reference to a movie clip or object
		*/
		public function Color(   $targetObj:DisplayObject=null, $colorValue:uint = 0xff3333) {
			// trace ( LINKAGE_ID + ' class instantiated');
			if ($targetObj == null) { return; }
			var newColorTransform:ColorTransform = $targetObj.transform.colorTransform;
			newColorTransform.color = $colorValue;
			$targetObj.transform.colorTransform = newColorTransform;
		}

		//////////////////////////////////////// Static ///////////////////////////////////////

		static public function setRGB(  $targetObj:DisplayObject = null, $colorValue:uint = 0xff3333) {
			return new Color ( $targetObj, $colorValue);
		}

	} // end class

} // end package

Initial URL
http://www.matthijskamstra.nl/blog/index.php/2008/07/23/from-as2-to-as3-where-did-it-go-setrgb/

Initial Description
I really like the use of constants and the dollar sign ($) in this class. I have only used $ in jQuery to designate objects. Looks like one might use $ in AS3 classes to designate/differentiate passed-in variables from internal method/global vars.

Initial Title
From AS2 to AS3 – Where did it go – setRGB | [mck]

Initial Tags
color

Initial Language
ActionScript 3