ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
spark.filters 

ColorMatrixFilter  - AS3 Flex

Packagespark.filters
Classpublic class ColorMatrixFilter
InheritanceColorMatrixFilter Inheritance BaseFilter Inheritance EventDispatcher Inheritance Object
Implements IBitmapFilter

Language Version: ActionScript 3.0
Product Version: Flex 4
Runtime Versions: Flash Player 10, AIR 1.5

The ColorMatrixFilter class lets you apply a 4 x 5 matrix transformation on the RGBA color and alpha values of every pixel in the input image to produce a result with a new set of RGBA color and alpha values. It allows saturation changes, hue rotation, luminance to alpha, and various other effects. You can apply the filter to any display object (that is, objects that inherit from the DisplayObject class), such as MovieClip, SimpleButton, TextField, and Video objects, as well as to BitmapData objects.

MXML SyntaxexpandedHide MXML Syntax

The <s:ColorMatrixFilter> tag inherits all of the tag attributes of its superclass and adds the following tag attributes:

  <s:ColorMatrixFilter
    Properties
    matrix="[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0]"
  />
  

View the examples

More examples

Learn more

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  matrix : Object
A comma delimited list of 20 doubles that comprise a 4x5 matrix applied to the rendered element.
ColorMatrixFilter
Public Methods
 MethodDefined By
  
ColorMatrixFilter(matrix:Array = null)
Constructor.
ColorMatrixFilter
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
Returns a copy of this filter object.
ColorMatrixFilter
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 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
Propagates a change event when the filter has changed.
BaseFilter
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
 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
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
Public Constants
 ConstantDefined By
Property Detail

matrix

property
matrix:Object

Language Version: ActionScript 3.0
Product Version: Flex 4
Runtime Versions: Flash Player 10, AIR 1.5

A comma delimited list of 20 doubles that comprise a 4x5 matrix applied to the rendered element. The matrix is in row major order -- that is, the first five elements are multipled by the vector [srcR,srcG,srcB,srcA,1] to determine the output red value, the second five determine the output green value, etc.

The value must either be an array or comma delimited string of 20 numbers.

The default value is [1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0].



Implementation
    public function get matrix():Object
    public function set matrix(value:Object):void
Constructor Detail

ColorMatrixFilter

()Constructor
public function ColorMatrixFilter(matrix:Array = null)

Language Version: ActionScript 3.0
Product Version: Flex 4
Runtime Versions: Flash Player 10, AIR 1.5

Constructor.

Parameters
matrix:Array (default = null) — An array of 20 items arranged as a 4 x 5 matrix.
Method Detail

clone

()method
public function clone():BitmapFilter

Language Version: ActionScript 3.0
Product Version: Flex 4
Runtime Versions: Flash Player 10, AIR 1.5

Returns a copy of this filter object.

Returns
BitmapFilter — A new ColorMatrixFilter instance with all of the same properties as the original one.
ColorMatrixFilterExample.mxml
<?xml version="1.0"?>
<!-- filters/examples/ColorMatrixFilterExample .mxml -->
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    creationComplete="createFilters()">
    
  <fx:Script><![CDATA[ 
     import spark.filters.*;
     import flash.filters.BitmapFilterQuality;
     import flash.filters.BitmapFilterType;
  
     private var myGreenMatrixFilter:ColorMatrixFilter;  
     private var myBlueMatrixFilter:ColorMatrixFilter;  
     private var myRedMatrixFilter:ColorMatrixFilter;  

     public function createFilters():void {        
         var greenMatrix:Array = new Array();
                greenMatrix = greenMatrix.concat([0, 0, 0, 0, 0]); // red
                greenMatrix = greenMatrix.concat([0, 1, 0, 0, 0]); // green
                greenMatrix = greenMatrix.concat([0, 0, 0, 0, 0]); // blue
                greenMatrix = greenMatrix.concat([0, 0, 0, 1, 0]); // alpha

         var blueMatrix:Array = new Array();
                blueMatrix = blueMatrix.concat([0, 0, 0, 0, 0]); // red
                blueMatrix = blueMatrix.concat([0, 0, 0, 0, 0]); // green
                blueMatrix = blueMatrix.concat([0, 0, 1, 0, 0]); // blue
                blueMatrix = blueMatrix.concat([0, 0, 0, 1, 0]); // alpha

         var redMatrix:Array = new Array();
                redMatrix = redMatrix.concat([1, 0, 0, 0, 0]); // red
                redMatrix = redMatrix.concat([0, 0, 0, 0, 0]); // green
                redMatrix = redMatrix.concat([0, 0, 0, 0, 0]); // blue
                redMatrix = redMatrix.concat([0, 0, 0, 1, 0]); // alpha

        myGreenMatrixFilter = new ColorMatrixFilter(greenMatrix);
        myBlueMatrixFilter = new ColorMatrixFilter(blueMatrix);
        myRedMatrixFilter = new ColorMatrixFilter(redMatrix);

        greenImage.filters = [myGreenMatrixFilter];
        blueImage.filters = [myBlueMatrixFilter];
        redImage.filters = [myRedMatrixFilter];
     }
  
  ]]></fx:Script>

    <s:VGroup>
        <s:VGroup>
            <s:Label text="Original Image"/>
            <mx:Image id="originalImage" source="@Embed(source='assets/Nokia_6630.png')"/>
        </s:VGroup>        

        <s:VGroup>
            <s:Label text="Green Matrix Image"/>
            <mx:Image id="greenImage" source="@Embed(source='assets/Nokia_6630.png')"/>
        </s:VGroup>        

        <s:VGroup>
            <s:Label text="Blue Matrix Image"/>
            <mx:Image id="blueImage" source="@Embed(source='assets/Nokia_6630.png')"/>
        </s:VGroup>        

        <s:VGroup>
            <s:Label text="Red Matrix Image"/>
            <mx:Image id="redImage" source="@Embed(source='assets/Nokia_6630.png')"/>
        </s:VGroup>        
    </s:VGroup>        
</s:Application>