Adobe® Flex® 4 Language Reference
Hide Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.geom 
ColorTransform 
Packageflash.geom
Classpublic class ColorTransform
InheritanceColorTransform Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

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

  • New red value = (old red value * redMultiplier) + redOffset
  • New green value = (old green value * greenMultiplier) + greenOffset
  • New blue value = (old blue value * blueMultiplier) + blueOffset
  • New alpha value = (old alpha value * alphaMultiplier) + alphaOffset

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 can use ColorTransform objects in the following ways:

  • In the colorTransform parameter of the colorTransform() method of the BitmapData class
  • As the colorTransform property of a Transform object (which can be used as the transform property of a display object)

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.

View the examples

See also



Public Properties
 PropertyDefined By
  alphaMultiplier : Number
A decimal value that is multiplied with the alpha transparency channel value.
ColorTransform
  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.
ColorTransform
  blueMultiplier : Number
A decimal value that is multiplied with the blue channel value.
ColorTransform
  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.
ColorTransform
  color : uint
The RGB color value for a ColorTransform object.
ColorTransform
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  greenMultiplier : Number
A decimal value that is multiplied with the green channel value.
ColorTransform
  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.
ColorTransform
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  redMultiplier : Number
A decimal value that is multiplied with the red channel value.
ColorTransform
  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.
ColorTransform
Public Methods
 MethodDefined By
  
ColorTransform(redMultiplier:Number = 1.0, greenMultiplier:Number = 1.0, blueMultiplier:Number = 1.0, alphaMultiplier:Number = 1.0, redOffset:Number = 0, greenOffset:Number = 0, blueOffset:Number = 0, alphaOffset:Number = 0)
Creates a ColorTransform object for a display object with the specified color channel values and alpha values.
ColorTransform
  
Concatenates the ColorTranform object specified by the second parameter with the current ColorTransform object and sets the current object as the result, which is an additive combination of the two color transformations.
ColorTransform
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
  
Formats and returns a string that describes all of the properties of the ColorTransform object.
ColorTransform
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail

alphaMultiplier

property
public var alphaMultiplier:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

If you set the alpha transparency value of a display object directly by using the alpha property of the DisplayObject instance, it affects the value of the alphaMultiplier property of that display object's transform.colorTransform property.

See also

alphaOffset

property 
public var alphaOffset:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

property 
public var blueMultiplier:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

blueOffset

property 
public var blueOffset:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

color

property 
color:uint

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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.

When you pass a value for this property, use 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.



Implementation
    public function get color():uint
    public function set color(value:uint):void

greenMultiplier

property 
public var greenMultiplier:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

greenOffset

property 
public var greenOffset:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

redMultiplier

property 
public var redMultiplier:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

redOffset

property 
public var redOffset:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

Constructor Detail

ColorTransform

()Constructor
public function ColorTransform(redMultiplier:Number = 1.0, greenMultiplier:Number = 1.0, blueMultiplier:Number = 1.0, alphaMultiplier:Number = 1.0, redOffset:Number = 0, greenOffset:Number = 0, blueOffset:Number = 0, alphaOffset:Number = 0)

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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

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

concat

()method
public function concat(second:flash.geom:ColorTransform):void

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

Concatenates the ColorTranform object specified by the second parameter with the current ColorTransform object and sets the current object as the result, which is an additive combination of the two color transformations. When you apply the concatenated ColorTransform object, the effect is the same as applying the second color transformation after the original color transformation.

Parameters

second:flash.geom:ColorTransform — The ColorTransform object to be combined with the current ColorTransform object.

toString

()method 
public function toString():String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 9, AIR 1.0

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.
ColorTransformExample.as

The following example uses the TransformExample class to create a simple sprite in the shape of a square filled with a gradient pattern. Each time the user clicks the square, the application transforms the colors of the square sprite, adding to the red color channel and lightening the blue color channel. This is accomplished with the following steps:
  1. The constructor creates a new sprite object target.
  2. The CustomButton() constructor calls the draw() method, which draws a gradient square in the sprite.
  3. The CustomButton() constructor adds a click event listener for the sprite, which is handled by the clickHandler() method.
  4. In the clickHandler() method, two properties are set to the redOffset and blueOffset properties of the current color transformation. Each is adjusted by 25. Then the transform.colorTransform property of the square sprite is modified to use the new offset values. Each time the user clicks the square, the call to the clickHandler() method modifies the color of the square, by augmenting its red color value and diminishing its blue color value.
package {
    import flash.display.Sprite;
    import flash.display.GradientType;
    import flash.geom.ColorTransform;
    import flash.events.MouseEvent;

    public class ColorTransformExample extends Sprite {
        public function ColorTransformExample() {
            var target:Sprite = new Sprite();
            draw(target);
            addChild(target);
            target.useHandCursor = true;
            target.buttonMode = true;
            target.addEventListener(MouseEvent.CLICK, clickHandler)
        }
        public function draw(sprite:Sprite):void {
            var red:uint = 0xFF0000;
            var green:uint = 0x00FF00;
            var blue:uint = 0x0000FF;
            var size:Number = 100;
            sprite.graphics.beginGradientFill(GradientType.LINEAR, [red, blue, green], [1, 0.5, 1], [0, 200, 255]);
            sprite.graphics.drawRect(0, 0, 100, 100);
        }
        public function clickHandler(event:MouseEvent):void {
            var rOffset:Number = transform.colorTransform.redOffset + 25;
            var bOffset:Number = transform.colorTransform.redOffset - 25;
            this.transform.colorTransform = new ColorTransform(1, 1, 1, 1, rOffset, 0, bOffset, 0);
        }
    }
}