ColorUtil (com.robertpenner.utils.ColorUtil)

com.robertpenner.utils.ColorUtil
class ColorUtil

The ColorUtil class includes a collection of utilities that allows for more intuitive color manipulation.

Availability:

ActionScript 2.0; Flash Player 6

Method summary

Method Description
setRGBStr(col:Color, hexStr:String) : Void

Specifies an RGB color for a Color object using a string hexadecimal value.

getRGBStr(col:Color) : String

Returns the R+G+B combination currently in use by the Color object as a string hexadecimal value.

setRGB2(col:Color, r:Number, g:Number, b:Number) : Void

Specifies an RGB color for a Color object using individual red, green, and blue values.

getRGB2(col:Color) : Object

Returns the R+G+B values currently in use by the Color object as individual red, green, and blue values.

reset(col:Color) : Void

Sets the color transform for a Color object to its default values.

setBrightness(col:Color, bright:Number) : Void

Specifies the brightness of a Color object.

getBrightness(col:Color) : Number

Returns the brightness of a Color object.

setBrightOffset(col:Color, offset:Number) : Void

Pushes a Color object towards black or white by an absolute amount.

getBrightOffset(col:Color) : Number

Returns the brightness offset value of a Color object.

setTint(col:Color, r:Number, g:Number, b:Number, percent:Number) : Void

Tints a color object with a Color according to a certain percentage.

getTint(col:Color) : Object

Returns the tint of a Color object.

setTint2(col:Color, rgb:Number, percent:Number) : Void

Tints a color object with a Color according to a certain percentage.

getTint2(col:Color) : Object

Returns the tint of a Color object.

setTintOffset(col:Color, r:Number, g:Number, b:Number) : Void

Tints a Color object with a color according to red, green, and blue values.

getTintOffset(col:Color) : Object

Returns the tint offset of a Color object.

setTintOffset2(col:Color, rgb:Number) : Void

Tints a Color object with a color according to an rgb value.

getTintOffset2(col:Color) : Number

Returns the tint offset of a Color object.

invert(col:Color) : Void

Performs a straightforward color inversion.

setNegative(col:Color, percent:Number) : Void

Inverts a Color object by a certain percentage.

getNegative(col:Color) : Number

Returns the negative percentage of a Color object.

setRed(col:Color, amount:Number) : Void

Specifies a red color value for a Color object.

getRed(col:Color) : Number

Returns the red color value of a Color object.

setGreen(col:Color, amount:Number) : Void

Specifies a green color value for a Color object.

getGreen(col:Color) : Number

Returns the green color value of a Color object.

setBlue(col:Color, amount:Number) : Void

Specifies a blue color value for a Color object.

getBlue(col:Color) : Number

Returns the blue color value of a Color object.

setRedPercent(col:Color, percent:Number) : Void

Specifies a red percentage value for a Color object.

getRedPercent(col:Color) : Number

Returns the red percentage value of a Color object.

setGreenPercent(col:Color, percent:Number) : Void

Specifies a green percentage value for a Color object.

getGreenPercent(col:Color) : Number

Returns the green percentage value of a Color object.

setBluePercent(col:Color, percent:Number) : Void

Specifies a blue percentage value for a Color object.

getBluePercent(col:Color) : Number

Returns the blue percentage value of a Color object.

setRedOffset(col:Color, offset:Number) : Void

Specifies a red offset value for a Color object.

getRedOffset(col:Color) : Number

Returns the red offset value of a Color object.

setGreenOffset(col:Color, offset:Number) : Void

Specifies a green offset value for a Color object.

getGreenOffset(col:Color) : Number

Returns the green offset value of a Color object.

setBlueOffset(col:Color, offset:Number) : Void

Specifies a blue offset value for a Color object.

getBlueOffset(col:Color) : Number

Returns the blue offset value of a Color object.

setRGBStr(col:Color, hexStr:String) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRGBStr(my_color, "#FFFF00");

Parameters

col:Color - The Color object to manipulate.

hexStr:String - The string hexadecimal color to be set.

Returns

Nothing.

Description

Specifies an RGB color for a Color object using a string hexadecimal value.


getRGBStr(col:Color) : String

Usage


var my_color:Color = new Color(my_mc);
my_color.setRGB(0x0000FF);
trace (ColorUtil.getRGBStr(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The string hexadecimal color.

Description

Returns the R+G+B combination currently in use by the Color object as a string hexadecimal value.


setRGB2(col:Color, r:Number, g:Number, b:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRGB2(my_color, 255, 0, 255);

Parameters

col:Color - The Color object to manipulate.

r:Number - The red color value.

g:Number - The green color value.

b:Number - The blue color value.

Returns

Nothing.

Description

Specifies an RGB color for a Color object using individual red, green, and blue values.


getRGB2(col:Color) : Object

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRGB2(my_color, 255, 0, 255);
var rgb:Object = ColorUtil.getRGB2(my_color);
trace (rgb.r);
trace (rgb.g);
trace (rgb.b);

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The RBG value object with r, g, and b properties.

Description

Returns the R+G+B values currently in use by the Color object as individual red, green, and blue values.


reset(col:Color) : Void

Usage


var my_color:Color = new Color(my_mc);
my_color.setRGB(0x0000FF);
ColorUtil.reset(my_color);

Parameters

col:Color - The Color object to manipulate.

Returns

Nothing.

Description

Sets the color transform for a Color object to its default values.


setBrightness(col:Color, bright:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBrightness(my_color, 50);

Parameters

col:Color - The Color object to manipulate.

bright:Number - A percentage value between -100 and 100. Positive values brighten the color. and negative values darken it.

Returns

Nothing.

Description

Specifies the brightness of a Color object.


getBrightness(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBrightness(my_color, 50);
trace (ColorUtil.getBrightness(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The brightness value.

Description

Returns the brightness of a Color object.


setBrightOffset(col:Color, offset:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBrightOffset(my_color, 140);

Parameters

col:Color - The Color object to manipulate.

offset:Number - A number between -255 and 255. Positive values push colors towards white; negative values towards black.

Returns

Nothing.

Description

Pushes a Color object towards black or white by an absolute amount.


getBrightOffset(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBrightOffset(my_color, 140);
trace (ColorUtil.getBrightOffset(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The brightness offset value.

Description

Returns the brightness offset value of a Color object.


setTint(col:Color, r:Number, g:Number, b:Number, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTint(my_color, 0, 0, 128, 50);

Parameters

col:Color - The Color object to manipulate.

r:Number - The red color value.

g:Number - The green color value.

b:Number - The blue color value.

percent:Number - The tint percentage.

Returns

Nothing.

Description

Tints a color object with a Color according to a certain percentage.


getTint(col:Color) : Object

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTint(my_color, 0, 0, 128, 50);
var tint:Object = ColorUtil.getTint(my_color);
trace (tint.r);
trace (tint.g);
trace (tint.b);
trace (tint.percent);

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The tint value object with r, g, b, and percent properties.

Description

Returns the tint of a Color object.


setTint2(col:Color, rgb:Number, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTint2(my_color, 0x0000FF, 100);

Parameters

col:Color - The Color object to manipulate.

rgb:Number - The rgb value.

percent:Number - The tint percentage.

Returns

Nothing.

Description

Tints a color object with a Color according to a certain percentage.


getTint2(col:Color) : Object

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTint2(my_color, 0x0000FF, 100);
var tint:Object = ColorUtil.getTint2(my_color);
trace (tint.rgb);
trace (tint.percent);

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The tint value object with rgb and percent properties.

Description

Returns the tint of a Color object.


setTintOffset(col:Color, r:Number, g:Number, b:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTintOffset(my_color, 0, 0, 128);

Parameters

col:Color - The Color object to manipulate.

r:Number - The red color value.

g:Number - The green color value.

b:Number - The blue color value.

Returns

Nothing.

Description

Tints a Color object with a color according to red, green, and blue values.


getTintOffset(col:Color) : Object

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTintOffset(my_color, 0, 0, 128);
var tint:Object = ColorUtil.getTintOffset(my_color);
trace (tint.r);
trace (tint.g);
trace (tint.b);

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The tint offset value object with r, g, and b properties.

Description

Returns the tint offset of a Color object.


setTintOffset2(col:Color, rgb:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTintOffset2(my_color, 0x000080);

Parameters

col:Color - The Color object to manipulate.

rgb:Number - The rgb value.

Returns

Nothing.

Description

Tints a Color object with a color according to an rgb value.


getTintOffset2(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setTintOffset2(my_color, 0x000080);
trace (ColorUtil.getTintOffset2(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The tint offset value object with an rgb properties.

Description

Returns the tint offset of a Color object.


invert(col:Color) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.invert(my_color);

Parameters

col:Color - The Color object to manipulate.

Returns

Nothing.

Description

Performs a straightforward color inversion.


setNegative(col:Color, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setNegative(my_color, 60);

Parameters

col:Color - The Color object to manipulate.

percent:Number - The negative percentage.

Returns

Nothing.

Description

Inverts a Color object by a certain percentage.


getNegative(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setNegative(my_color, 60);
trace (ColorUtil.getNegative(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The negative percentage.

Description

Returns the negative percentage of a Color object.


setRed(col:Color, amount:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRed(my_color, 128);

Parameters

col:Color - The Color object to manipulate.

amount:Number - The red color value.

Returns

Nothing.

Description

Specifies a red color value for a Color object.


getRed(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRed(my_color, 128);
trace (ColorUtil.getRed(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The red color value.

Description

Returns the red color value of a Color object.


setGreen(col:Color, amount:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreen(my_color, 128);

Parameters

col:Color - The Color object to manipulate.

amount:Number - The green color value.

Returns

Nothing.

Description

Specifies a green color value for a Color object.


getGreen(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreen(my_color, 128);
trace (ColorUtil.getGreen(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The green color value.

Description

Returns the green color value of a Color object.


setBlue(col:Color, amount:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBlue(my_color, 128);

Parameters

col:Color - The Color object to manipulate.

amount:Number - The blue color value.

Returns

Nothing.

Description

Specifies a blue color value for a Color object.


getBlue(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBlue(my_color, 128);
trace (ColorUtil.getBlue(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The blue color value.

Description

Returns the blue color value of a Color object.


setRedPercent(col:Color, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRedPercent(my_color, 50);

Parameters

col:Color - The Color object to manipulate.

percent:Number - The red percentage value.

Returns

Nothing.

Description

Specifies a red percentage value for a Color object.


getRedPercent(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRedPercent(my_color, 50);
trace (ColorUtil.getRedPercent(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The red percentage value.

Description

Returns the red percentage value of a Color object.


setGreenPercent(col:Color, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreenPercent(my_color, 50);

Parameters

col:Color - The Color object to manipulate.

percent:Number - The green percentage value.

Returns

Nothing.

Description

Specifies a green percentage value for a Color object.


getGreenPercent(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreenPercent(my_color, 50);
trace (ColorUtil.getGreenPercent(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The green percentage value.

Description

Returns the green percentage value of a Color object.


setBluePercent(col:Color, percent:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBluePercent(my_color, 50);

Parameters

col:Color - The Color object to manipulate.

percent:Number - The blue percentage value.

Returns

Nothing.

Description

Specifies a blue percentage value for a Color object.


getBluePercent(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBluePercent(my_color, 50);
trace (ColorUtil.getBluePercent(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The blue percentage value.

Description

Returns the blue percentage value of a Color object.


setRedOffset(col:Color, offset:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRedOffset(my_color, -128);

Parameters

col:Color - The Color object to manipulate.

percent: - The red offset value.

Returns

Nothing.

Description

Specifies a red offset value for a Color object.


getRedOffset(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setRedOffset(my_color, -128);
trace (ColorUtil.getRedOffset(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The red offset value.

Description

Returns the red offset value of a Color object.


setGreenOffset(col:Color, offset:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreenOffset(my_color, -128);

Parameters

col:Color - The Color object to manipulate.

percent: - The green offset value.

Returns

Nothing.

Description

Specifies a green offset value for a Color object.


getGreenOffset(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setGreenOffset(my_color, -128);
trace (ColorUtil.getGreenOffset(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The green offset value.

Description

Returns the green offset value of a Color object.


setBlueOffset(col:Color, offset:Number) : Void

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBlueOffset(my_color, -128);

Parameters

col:Color - The Color object to manipulate.

percent: - The blue offset value.

Returns

Nothing.

Description

Specifies a blue offset value for a Color object.


getBlueOffset(col:Color) : Number

Usage


var my_color:Color = new Color(my_mc);
ColorUtil.setBlueOffset(my_color, -128);
trace (ColorUtil.getBlueOffset(my_color));

Parameters

col:Color - The Color object from which to retrieve the value.

Returns

The blue offset value.

Description

Returns the blue offset value of a Color object.