ColorUtils

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

Summary


Class methods
  • getHexNumber (inHexColor:Object) : Number
    • Retrieves the hex number (0xff0033) from a hex number or hex string ("ff0033").
  • getHexString (inHexColorNumber:Number) : String
    • Returns a hex number (0xff0033 or 6697932) as a hexadecimal String, for instance "ff0033".
  • setColor (inMC:MovieClip, inHexColor:Object) : Void
    • Set a movieclip's color to a color number (0xff3300) or string ("ff3300").
  • setTransform (inMC:MovieClip, inTransformObject:Object) : Void
    • Sets the movieclip's colors using Color.setTransform.
  • getMixColorNumber (inStartColor:Object, inMixColor:Object, inPercentage:Number) : Number
    • Creates and returns a hexadecimal number that is a mix of two color numbers.
  • getTransformObject (inHexColor:Object, inComponentPercentage:Number) : Object
    • Creates a color transform object from a hex number/hex string.
  • setMixColor (inMC:MovieClip, inStartColor:Object, inMixColor:Object, inPercentage:Number) : Void
    • Sets a movieclip's color by mixing two colors using Color.setRGB.
  • getMixTransformObject (inStartTransform:Object, inMixTransform:Object, inPercentage:Number) : Object
    • Mixes two color transform objects and returns the new transform object.
  • setMixTransform (inMC:MovieClip, inStartTransform:Object, inMixTransform:Object, inPercentage:Number) : Object
    • Sets a movieclip's color by mixing two colors using Color.setTransform.
  • restoreColor (inMC:MovieClip) : Void
    • Restores the true color of the movieclip, making it appear as in the Library.
  • setBaseColor (inMC:MovieClip, inBaseColor:Object, inShouldSetColor:Boolean) : Void
    • Stores a color variable as "base color" property in the movieclip.
  • setMixBaseColor (inMC:MovieClip, inStartColor:Object, inMixColor:Object, inPercentage:Number, inShouldSetColor:Boolean) : Void
    • Creates the base color by mixing two colors.
  • getBaseColor (inMC:MovieClip) : Number
    • Retrieves the stored base color variable from the movieclip.
  • setToBaseColor (inMC:MovieClip) : Void
    • Sets the color of a movieclip (back) to the color value stored in its base color.
  • HEXtoRGB (inHexNumber:Number) : Object
  • mixValues (inA:Number, inB:Number, inMix:Number) : Number
    • Mixes two numbers by a mix percentage value.

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'};

HEXtoRGB

static private function HEXtoRGB (
inHexNumber:Number) : Object

Parameters:
inHexNumber:
the hex number to derive a rgb color object from
Returns:
  • An object with the properties r, g, b.

mixValues

static private function mixValues (
inA:Number, inB:Number, inMix:Number) : Number

Mixes two numbers by a mix percentage value.
Parameters:
inA :
first number to mix
inB :
second number to mix
inMix:
percentage value (0-100) by which the numbers should be mixed
Returns:
  • The outcome of the mix calculation (a value between number a and number b)
Example:
  • The following values returns 128:
    AQCOmixValues(255, 128, 100);
    The following values returns 191.5:
    AQCOmixValues(255, 128, 50);

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:

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 
    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 );