flash.geom

Class ColorTransform

Object


public class ColorTransform
extends Object

Player version: Flash Player 8

The ColorTransform class lets you mathematically adjust all of the color values in a movie clip. The color adjustment function or color transformation can be applied to all four channels: red, green, blue, and alpha transparency.

When a ColorTransform object is applied to a movie clip, a new value for each color channel is calculated like this:

If any of the color channel values is greater than 255 after the calculation, it is set to 255. If it is less than 0, it is set to 0.

You must use the new ColorTransform() constructor to create a ColorTransform object before you can call the methods of the ColorTransform object.

Color transformations do not apply to the background color of a movie clip (such as a loaded SWF object). They apply only to graphics and symbols that are attached to the movie clip.

See also
Transform.colorTransform



Property Summary
alphaMultiplier : Number
A decimal value that is multiplied by the alpha transparency channel value.
alphaOffset : Number
A number from -255 to 255 that is added to the alpha transparency channel value after it has been multiplied by the alphaMultiplier value.
blueMultiplier : Number
A decimal value that is multiplied by the blue channel value.
blueOffset : Number
A number from -255 to 255 that is added to the blue channel value after it has been multiplied by the blueMultiplier value.
greenMultiplier : Number
A decimal value that is multiplied by the green channel value.
greenOffset : Number
A number from -255 to 255 that is added to the green channel value after it has been multiplied by the greenMultiplier value.
redMultiplier : Number
A decimal value that is multiplied by the red channel value.
redOffset : Number
A number from -255 to 255 that is added to the red channel value after it has been multiplied by the redMultiplier value.
rgb : Number
The RGB color value for a ColorTransform object.

Properties inherited from class Object
__proto__, __resolve, constructor, prototype


Constructor Summary
ColorTransform([redMultiplier:Number], [greenMultiplier:Number], [blueMultiplier:Number], [alphaMultiplier:Number], [redOffset:Number], [greenOffset:Number], [blueOffset:Number], [alphaOffset:Number])
Creates a ColorTransform object for a display object with the specified color channel values and alpha values.


Method Summary
concat(second:ColorTransform) : Void
Applies a second, additive color transformation to the movie clip.
toString() : String
Formats and returns a string that describes all of the properties of the ColorTransform object.

Methods inherited from class Object
addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch


Property Detail

alphaMultiplier Property

public alphaMultiplier : Number

Player version: Flash Player 8

A decimal value that is multiplied by the alpha transparency channel value.

If you set the alpha transparency value of a movie clip directly by using the MovieClip._alpha property, it affects the value of the alphaMultiplier property of that movie clip's ColorTransform object.

Example
The following example creates the ColorTransform object colorTrans and adjusts its alphaMultiplier value from 1 to .5.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.alphaMultiplier);        // 1

colorTrans.alphaMultiplier = .5;    
trace(colorTrans.alphaMultiplier);        // .5

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}

See also
MovieClip._alpha

alphaOffset Property

public alphaOffset : Number

Player version: Flash Player 8

A number from -255 to 255 that is added to the alpha transparency channel value after it has been multiplied by the alphaMultiplier value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its alphaOffset value from 0 to -128.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.alphaOffset);            // 0

colorTrans.alphaOffset = -128;
trace(colorTrans.alphaOffset);            // -128

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


blueMultiplier Property

public blueMultiplier : Number

Player version: Flash Player 8

A decimal value that is multiplied by the blue channel value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its blueMultiplier value from 1 to .5.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.blueMultiplier);        // 1

colorTrans.blueMultiplier = .5;
trace(colorTrans.blueMultiplier);        // .5

var rect:MovieClip = createRectangle(20, 80, 0x0000FF);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


blueOffset Property

public blueOffset : Number

Player version: Flash Player 8

A number from -255 to 255 that is added to the blue channel value after it has been multiplied by the blueMultiplier value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its blueOffset value from 0 to 255.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.blueOffset);            // 0

colorTrans.blueOffset = 255;
trace(colorTrans.blueOffset);            // 255

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


greenMultiplier Property

public greenMultiplier : Number

Player version: Flash Player 8

A decimal value that is multiplied by the green channel value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its greenMultiplier from 1 to .5.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.greenMultiplier);        // 1

colorTrans.greenMultiplier = .5;
trace(colorTrans.greenMultiplier);        // .5

var rect:MovieClip = createRectangle(20, 80, 0x00FF00);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


greenOffset Property

public greenOffset : Number

Player version: Flash Player 8

A number from -255 to 255 that is added to the green channel value after it has been multiplied by the greenMultiplier value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its greenOffset value from 0 to 255.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.greenOffset);            // 0

colorTrans.greenOffset = 255;
trace(colorTrans.greenOffset);            // 255

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


redMultiplier Property

public redMultiplier : Number

Player version: Flash Player 8

A decimal value that is multiplied by the red channel value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its redMultiplier value from 1 to .5.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.redMultiplier);        // 1

colorTrans.redMultiplier = .5;
trace(colorTrans.redMultiplier);        // .5

var rect:MovieClip = createRectangle(20, 80, 0xFF0000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


redOffset Property

public redOffset : Number

Player version: Flash Player 8

A number from -255 to 255 that is added to the red channel value after it has been multiplied by the redMultiplier value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its redOffset value from 0 to 255.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.redOffset);            // 0

colorTrans.redOffset = 255;
trace(colorTrans.redOffset);            // 255

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


rgb Property

public rgb : Number

Player version: Flash Player 8

The RGB color value for a ColorTransform object.

When you set this property, it changes the three color offset values (redOffset, greenOffset, and blueOffset) accordingly, and it sets the three color multiplier values (redMultiplier, greenMultiplier, and blueMultiplier) to 0. The alpha transparency multiplier and offset values do not change.

Pass a value for this property in the format: 0xRRGGBB. RR, GG, and BB each consist of two hexadecimal digits that specify the offset of each color component. The 0x tells the ActionScript compiler that the number is a hexadecimal value.

Example
The following example creates the ColorTransform object colorTrans and adjusts its rgb value to 0xFF0000.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
trace(colorTrans.rgb);                     // 0

colorTrans.rgb = 0xFF0000;
trace(colorTrans.rgb);                     // 16711680                
trace("0x" + colorTrans.rgb.toString(16)); // 0xff0000

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}



Constructor Detail

ColorTransform Constructor

public ColorTransform([redMultiplier:Number], [greenMultiplier:Number], [blueMultiplier:Number], [alphaMultiplier:Number], [redOffset:Number], [greenOffset:Number], [blueOffset:Number], [alphaOffset:Number])

Player version: Flash Player 8

Creates a ColorTransform object for a display object with the specified color channel values and alpha values.

Parameters
redMultiplier:Number [optional] — The value for the red multiplier, in the range from 0 to 1. The default value is 1.
greenMultiplier:Number [optional] — The value for the green multiplier, in the range from 0 to 1. The default value is 1.
blueMultiplier:Number [optional] — The value for the blue multiplier, in the range from 0 to 1. The default value is 1.
alphaMultiplier:Number [optional] — The value for the alpha transparency multiplier, in the range from 0 to 1. The default value is 1.
redOffset:Number [optional] — The offset for the red color channel value (-255 to 255). The default value is 0.
greenOffset:Number [optional] — The offset for the green color channel value (-255 to 255). The default value is 0.
blueOffset:Number [optional] — The offset for the blue color channel value (-255 to 255). The default value is 0.
alphaOffset:Number [optional] — The offset for alpha transparency channel value (-255 to 255). The default value is 0.

Example
The following example creates a ColorTransform object called greenTransform:
var greenTransform:flash.geom.ColorTransform = new flash.geom.ColorTransform(0.5, 1.0, 0.5, 0.5, 10, 10, 10, 0);

The following example creates the ColorTransfrom object colorTrans_1 with the default constructor values. The fact that colorTrans_1 and colorTrans_2 trace the same values is evidence that the default constructor values are used.
import flash.geom.ColorTransform;

var colorTrans_1:ColorTransform = new ColorTransform(1, 1, 1, 1, 0, 0, 0, 0);
trace(colorTrans_1); 
//(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)

var colorTrans_2:ColorTransform = new ColorTransform();
trace(colorTrans_2); 
//(redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)



Method Detail

concat Method

public concat(second:ColorTransform) : Void

Player version: Flash Player 8

Applies a second, additive color transformation to the movie clip. The second set of transformation parameters is applied to the colors of the movie clip after the first transformation has been completed.

Parameters
second:ColorTransform — A second ColorTransform object to be combined with the current ColorTransform object.

Example
The following example concatenates the ColorTransform object colorTrans_2 to colorTrans_1 resulting in a full red offset combined with a .5 alpha multiplier.
import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans_1:ColorTransform = new ColorTransform(1, 1, 1, 1, 255, 0, 0, 0);
trace(colorTrans_1);        
// (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=255, greenOffset=0, blueOffset=0, alphaOffset=0)

var colorTrans_2:ColorTransform = new ColorTransform(1, 1, 1, .5, 0, 0, 0, 0);
trace(colorTrans_2);        
// (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=0.5, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)

colorTrans_1.concat(colorTrans_2);
trace(colorTrans_1);        
// (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=0.5, redOffset=255, greenOffset=0, blueOffset=0, alphaOffset=0)

var rect:MovieClip = createRectangle(20, 80, 0x000000);
var trans:Transform = new Transform(rect);
trans.colorTransform = colorTrans_1;

function createRectangle(width:Number, height:Number, color:Number, scope:MovieClip):MovieClip {
    scope = (scope == undefined) ? this : scope;
    var depth:Number = scope.getNextHighestDepth();
    var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
    mc.beginFill(color);
    mc.lineTo(0, height);
    mc.lineTo(width, height);
    mc.lineTo(width, 0);
    mc.lineTo(0, 0);
    return mc;
}


toString Method

public toString() : String

Player version: Flash Player 8

Formats and returns a string that describes all of the properties of the ColorTransform object.

Returns
String — A string that lists all of the properties of the ColorTransform object.

Example
The following example creates the ColorTransform object colorTrans and calls its toSting() method. This method results in a string with the following format: (redMultiplier=RM, greenMultiplier=GM, blueMultiplier=BM, alphaMultiplier=AM, redOffset=RO, greenOffset=GO, blueOffset=BO, alphaOffset=AO).
import flash.geom.ColorTransform;

var colorTrans:ColorTransform = new ColorTransform(1, 2, 3, 4, -255, -128, 128, 255);
trace(colorTrans.toString());        
// (redMultiplier=1, greenMultiplier=2, blueMultiplier=3, alphaMultiplier=4, redOffset=-255, greenOffset=-128, blueOffset=128, alphaOffset=255)