Access keys

ColorUtils

Kind of class: class
Inherits from: none
Author: Arthur Clemens
Classpath: org.asapframework.util.ColorUtils
File last modified: Thursday, 12 October 2006, 11:11:37
A collection of color utility functions.

Class methods

getBaseColor

static function getBaseColor (
inMC:MovieClip) : Number
Retrieves the stored base color variable from the movieclip.
The base color must have been set before calling this method (see setBaseColor).
Parameters:
inMC:
movieclip to retrieve the property from
Returns:
The color hex number (for instance 0xff3300).

getHexNumber

static function getHexNumber (
inHexColor:Object) : Number
Retrieves the hex number (0xff0033) from a hex number or hex string ("ff0033").
Parameters:
inHexColor:
a hex number (0xff0033) or hex string ("ff0033")
Returns:
A hex number (for instance 0xff3300).

getHexString

static function getHexString (
inHexColorNumber:Number) : String
Returns a hex number (0xff0033 or 6697932) as a hexadecimal String, for instance "ff0033".
Parameters:
inHexColorNumber:
a hex number (0xff0033 or 6697932)
Returns:
A hex String (for instance "ff3300").

getMixColorNumber

static function getMixColorNumber (
inStartColor:Object, inMixColor:Object, inPercentage:Number) : Number
Creates and returns a hexadecimal number that is a mix of two color numbers.
Parameters:
inStartColor:
the start color to mix; hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inMixColor :
the color that is mixed in (the amount of which is given by inPercentage); hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inPercentage:
the amount of mix color that is added to the start color; a value between 0.0 and 1.0
Returns:
The mixed hexadecimal number value.

getMixTransformObject

static function getMixTransformObject (
inStartTransform:Object, inMixTransform:Object, inPercentage:Number) : Object
Mixes two color transform objects and returns the new transform object.
Parameters:
inStartTransform:
start color (color transformation object); use getTransformObject to create a color transform object from a hex number
inMixTransform :
mix color (color transformation object)
inPercentage :
the amount of mix color that is added to the start color; a value between 0.0 and 1.0
Returns:
The mixed color transform object; see setTransform for a description of the transform object.

getTransformObject

static function getTransformObject (
inHexColor:Object, inComponentPercentage:Number) : Object
Creates a color transform object from a hex number/hex string.
A transform object has these properties:
ra is the percentage for the red component (-100 to 100)
rb is the offset for the red component (-255 to 255)
ga is the percentage for the green component (-100 to 100)
gb is the offset for the green component (-255 to 255)
ba is the percentage for the blue component (-100 to 100)
bb is the offset for the blue component (-255 to 255)
aa is the percentage for alpha (-100 to 100)
ab is the offset for alpha (-255 to 255)
Parameters:
inHexColor :
the color to use for the color component offsets; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inComponentPercentage:
(optional) the percentage value used for ra, ga, ba and aa; default 100 is assumed; use values greater than 100 for light effects
Returns:
A color transform object:
{ ra: [componentPercentage value], rb: [color r value], 
  ga: [componentPercentage value], gb: [color g value],
  ba: [componentPercentage value], bb: [color b value],
  aa: [componentPercentage value], ab: '0'};

restoreColor

static function restoreColor (
inMC:MovieClip) : Void
Restores the true color of the movieclip, making it appear as in the Library.
Parameters:
inMC:
movieclip or button to set the color of
Example:
The following code first sets the movieclip color to red, then restores it again:
ColorUtils.setColor( clip_mc, 0xff0000 );
ColorUtils.restoreColor, clip_mc );

setBaseColor

static function setBaseColor (
inMC:MovieClip, inBaseColor:Object, inShouldSetColor:Boolean) : Void
Stores a color variable as "base color" property in the movieclip.
Use the base color when you plan to change the color of the movieclip, and you want to revert or animate back to the original set color.
For instance, org.asapframework.util.actionqueue.AQColor.mixColors allows to use the base color (using the string "base") as mix color.
Parameters:
inMC :
movieclip that will store the property
inBaseColor :
a color hex number (for instance 0xff3300) or hex string ("ff3300"); you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inShouldSetColor:
(optional) if true the movieclip's color is set immediately using Color.setRGB(baseColorNum); default is false (no color change)
Implementation note:
The color number is stored in the movieclip's custom property _ASAP_baseColorNum.

setColor

static function setColor (
inMC:MovieClip, inHexColor:Object) : Void
Set a movieclip's color to a color number (0xff3300) or string ("ff3300").
Parameters:
inMC :
the movieclip to set the color of
inHexColor:
hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
Example:
This example turns a movieclip red:
ColorUtils.setColor( clip_mc, 0xff0000 );
THe following line makes it yellow:
ColorUtils.setColor( clip_mc, "ffff00" );
Implementation note:
Calls Color.setRGB(hexColorNum).

setMixBaseColor

static function setMixBaseColor (
inMC:MovieClip, inStartColor:Object, inMixColor:Object, inPercentage:Number, inShouldSetColor:Boolean) : Void
Creates the base color by mixing two colors.
Parameters:
inMC :
movieclip that will store the property
inStartColor :
the start color to mix; hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inMixColor :
the color that is mixed in (the amount of which is given by inPercentage); hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inPercentage :
the amount of mix color that is added to the start color; a value between 0.0 and 1.0
inShouldSetColor:
(optional) if true the movieclip's color is set immediately using Color.setRGB(baseColorNum); default is false (no color change)
Implementation note:

setMixColor

static function setMixColor (
inMC:MovieClip, inStartColor:Object, inMixColor:Object, inPercentage:Number) : Void
Sets a movieclip's color by mixing two colors using Color.setRGB.
Parameters:
inMC :
the movieclip to set the color of
inStartColor:
the start color to mix; hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inMixColor :
the color that is mixed in (the amount of which is given by inPercentage); hexadecimal number (0xff3300) or string ("ff3300") of the new color; you can use negative hex numbers as well: (-0xff3300 or "-ff3300")
inPercentage:
the amount of mix color that is added to the start color; a value between 0.0 and 1.0
Example:
This code sets the color of a movieclip to dark orange (40% of black mixed into ff6600):
ColorUtils.setMixColor( movies_mc.title_mc, 0xff6600, 0x000000, 0.4 );
Implementation note:
Calls setColor.

setMixTransform

static function setMixTransform (
inMC:MovieClip, inStartTransform:Object, inMixTransform:Object, inPercentage:Number) : Object
Sets a movieclip's color by mixing two colors using Color.setTransform.
Parameters:
inMC :
the movieclip to set the color of
inStartTransform:
start color (color transformation object); use getTransformObject to create a color transform object from a hex number
inMixTransform :
mix color (color transformation object)
inPercentage :
the amount of mix color that is added to the start color; a value between 0.0 and 1.0
Returns:
The mixed color transform object; see setTransform for a description of the transform object.
Example:
forthcoming
Implementation note:

setToBaseColor

static function setToBaseColor (
inMC:MovieClip) : Void
Sets the color of a movieclip (back) to the color value stored in its base color. The base color must have been set before calling this method.
Parameters:
inMC:
movieclip or button to set the color of

setTransform

static function setTransform (
inMC:MovieClip, inTransformObject:Object) : Void
Sets the movieclip's colors using Color.setTransform.
Parameters:
inMC :
movieclip which color should be transformed
inTransformObject:
the color transform object to set the movieclip's color.
A transform object has these properties:
ra is the percentage for the red component (-100 to 100)
rb is the offset for the red component (-255 to 255)
ga is the percentage for the green component (-100 to 100)
gb is the offset for the green component (-255 to 255)
ba is the percentage for the blue component (-100 to 100)
bb is the offset for the blue component (-255 to 255)
aa is the percentage for alpha (-100 to 100)
ab is the offset for alpha (-255 to 255)
Example:
var t:Object = { ra: '50', rb: '244', 
                 ga: '40', gb: '112',
                 ba: '12', bb: '90',
                 aa: '100', ab: '0' };
ColorUtils.setTransform( my_mc, t );
You can also create a transform object from a hex color using getTransformObject:
var t:Object = ColorUtils.getTransformObject( 0xff0000 );
ColorUtils.setTransform( my_mc, t );