fl.motion

# Color - AS3 Flash

Package | fl.motion
Class | public class Color
Inheritance | Color ColorTransform Object

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

The Color class extends the Flash Player ColorTransform class, adding the ability to control brightness and tint. It also contains static methods for interpolating between two ColorTransform objects or between two color numbers.

View the examples

Related API Elements

ColorTransform class
Motion XML Elements

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined 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
|  | brightness : Number The percentage of brightness, as a decimal between -1 and 1. | Color
|  | color : uint The RGB color value for a ColorTransform object. | ColorTransform
|  | constructor : 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
|  | 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
|  | tintColor : uint The tinting color value in the 0xRRGGBB format. | Color
|  | tintMultiplier : Number The percentage to apply the tint color, as a decimal value between 0 and 1. | Color

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | Color(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) Constructor for Color instances. | Color
|  | concat(second:flash.geom:ColorTransform):void 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
|  | fromXML(xml:XML):Color [static] Creates a Color instance from XML. | Color
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint [static] Blends smoothly from one color value to another. | Color
|  | interpolateTransform(fromColor:flash.geom:ColorTransform, toColor:flash.geom:ColorTransform, progress:Number):flash.geom:ColorTransform [static] Blends smoothly from one ColorTransform object to another. | Color
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | setTint(tintColor:uint, tintMultiplier:Number):void Sets the tint color and amount at the same time. | Color
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Formats and returns a string that describes all of the properties of the ColorTransform object. | ColorTransform
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Property Detail

### brightness

property

`brightness:Number`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

The percentage of brightness, as a decimal between `-1` and `1`. Positive values lighten the object, and a value of `1` turns the object completely white. Negative values darken the object, and a value of `-1` turns the object completely black.

The default value is `0.`

Implementation
`public function get brightness():Number`
`public function set brightness(value:Number):void`

### tintColor

property

`tintColor:uint`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

The tinting color value in the 0xRRGGBB format.

The default value is `0x000000 (black).`

Implementation
`public function get tintColor():uint`
`public function set tintColor(value:uint):void`

### tintMultiplier

property

`tintMultiplier:Number`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

The percentage to apply the tint color, as a decimal value between `0` and `1`. When `tintMultiplier = 0`, the target object is its original color and no tint color is visible. When `tintMultiplier = 1`, the target object is completely tinted and none of its original color is visible.

The default value is `0.`

Implementation
`public function get tintMultiplier():Number`
`public function set tintMultiplier(value:Number):void`
Constructor Detail

### Color

()
Constructor

`public function Color(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

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Constructor for Color instances.

Parameters

| `redMultiplier:Number` (default = `1.0`)`` — The percentage to apply the color, as a decimal value between 0 and 1.
| `greenMultiplier:Number` (default = `1.0`)`` — The percentage to apply the color, as a decimal value between 0 and 1.
| `blueMultiplier:Number` (default = `1.0`)`` — The percentage to apply the color, as a decimal value between 0 and 1.
| `alphaMultiplier:Number` (default = `1.0`)`` — A decimal value that is multiplied with the alpha transparency channel value, as a decimal value between 0 and 1.
| `redOffset:Number` (default = `0`)`` — A number from -255 to 255 that is added to the red channel value after it has been multiplied by the `redMultiplier` value.
| `greenOffset:Number` (default = `0`)`` — A number from -255 to 255 that is added to the green channel value after it has been multiplied by the `greenMultiplier` value.
| `blueOffset:Number` (default = `0`)`` — A number from -255 to 255 that is added to the blue channel value after it has been multiplied by the `blueMultiplier` value.
| `alphaOffset:Number` (default = `0`)`` — A number from -255 to 255 that is added to the alpha channel value after it has been multiplied by the `alphaMultiplier` value.

Method Detail

### fromXML

()
method

`public static function fromXML(xml:XML):Color`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Creates a Color instance from XML.

Parameters

| `xml:XML` — An E4X XML object containing a `<color>` node from Motion XML.

Returns

| `Color` — A Color instance that matches the XML description.

### interpolateColor

()
method

`public static function interpolateColor(fromColor:uint, toColor:uint, progress:Number):uint`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Blends smoothly from one color value to another.

Parameters

| `fromColor:uint` — The starting color value, in the 0xRRGGBB or 0xAARRGGBB format.
| `toColor:uint` — The ending color value, in the 0xRRGGBB or 0xAARRGGBB format.
| `progress:Number` — The percent of the transition as a decimal, where `0` is the start and `1` is the end.

Returns

| `uint` — The interpolated color value, in the 0xRRGGBB or 0xAARRGGBB format.

### interpolateTransform

()
method

`public static function interpolateTransform(fromColor:flash.geom:ColorTransform, toColor:flash.geom:ColorTransform, progress:Number):flash.geom:ColorTransform`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Blends smoothly from one ColorTransform object to another.

Parameters

| `fromColor:flash.geom:ColorTransform` — The starting ColorTransform object.
| `toColor:flash.geom:ColorTransform` — The ending ColorTransform object.
| `progress:Number` — The percent of the transition as a decimal, where `0` is the start and `1` is the end.

Returns

| `flash.geom:ColorTransform` — The interpolated ColorTransform object.

### setTint

()
method

`public function setTint(tintColor:uint, tintMultiplier:Number):void`

Language Version: | ActionScript 3.0

Product Version: | Flash CS3

Runtime Versions: | Flash Player 9.0.28.0, AIR 1.0

Sets the tint color and amount at the same time.

Parameters

| `tintColor:uint` — The tinting color value in the 0xRRGGBB format.
| `tintMultiplier:Number` — The percentage to apply the tint color, as a decimal value between `0` and `1`. When `tintMultiplier = 0`, the target object is its original color and no tint color is visible. When `tintMultiplier = 1`, the target object is completely tinted and none of its original color is visible.

Examples How to use this example
ColorExample.as
This example applies color transitions to a MovieClip using the static method interpolateColor. It could just as easily be used with a Sprite. This example draws a MovieClip of a square shape; clicking on the stage performs a color transition on the MovieClip. Also shown is the use of the setTint method, in this case to set a tint to the start_color.
Copy

    import fl.transitions.Tween;
    import fl.transitions.TweenEvent;
    import fl.transitions.easing.Strong;
    import fl.motion.Color;
    import flash.events.Event;
    import flash.geom.ColorTransform;

    var start_color:Color = new Color();
    start_color.setTint(0xFF0000, 0.5);
    var final_color:uint=0x006699;
    var clip_mc:MovieClip=new MovieClip();
    clip_mc.graphics.beginFill(start_color,1);
    clip_mc.graphics.drawRect(200,200,200,200);
    clip_mc.graphics.endFill();
    addChild(clip_mc);

    var colorInfo:ColorTransform=clip_mc.transform.colorTransform;
    function initTween(event:MouseEvent):void
    {
        var my_tween:Tween=new Tween(clip_mc,'alpha',Strong.easeOut,0,1,1,true);
        my_tween.addEventListener(TweenEvent.MOTION_CHANGE,tweenToFinal);
    }
    function tweenToFinal(event:TweenEvent):void
    {
        colorInfo.color=Color.interpolateColor(start_color,final_color,event.position);
        clip_mc.transform.colorTransform=colorInfo;
    }
    stage.addEventListener(MouseEvent.CLICK,initTween);

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00