The ColorMatrixFilter ClassThe ColorMatrixFilter class lets you apply a 4x5 matrix object to the RGBA of every pixel in an object. It is important when using this class to import it first at the beginning of your script, like this: import flash.filters.ColorMatrixFilter; To instantiate a new instance of the ColorMatrixFilter class, use this code as a template: var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
Example: This example will create a small blue square using the drawing API and apply the ColorMatrixFilter filter to it to make it pink: import flash.filters.ColorMatrixFilter; //create the movie clip to display the filter var rec_mc:MovieClip = this.createEmptyMovieClip("rec_mc", 1); //move the rectangle towards the center of the stage rec_mc._x = rec_mc._y = 200; //draw a squar inside the movie clip rec_mc.lineStyle(0,0x000000,0); rec_mc.beginFill(0x397dce, 100); rec_mc.lineTo(100,0); rec_mc.lineTo(100,100); rec_mc.lineTo(0,100); rec_mc.lineTo(0,0); rec_mc.endFill(); //create the matrix var matrix:Array = new Array(0, 0, 0, 3, 3, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, .5, 2); //create the filter var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix); //apply the filter rec_mc.filters = new Array(myFilter); Because the properties of this object match the parameters identically, they will be skipped. MethodscloneAvailability: FP:8, AS:1.0 Generic Template: myFilter.clone() Returns: ColorMatrixFilter An exact copy of the ColorMatrixFilter will be returned. Description: This method will create a duplicate copy of the ColorMatrixFilter it is called on. Example: This example will create a filter, clone it, and then walk through all the properties to see that they match: import flash.filters.ColorMatrixFilter; //create the matrix var matrix:Array = new Array(0, 0, 0, 3, 3, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, .5, 2); //create the filter var myFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix); //create a copy var myNewFilter:ColorMatrixFilter = myFilter.clone(); //walk through and display each property for(each in myNewFilter){ trace(each + ": " + myNewFilter[each]); } //output:clone: [type Function] //matrix: 0,0,0,3,3,1,1,0,0,1,1,1,1,0,0,0,0,0,0.5,2 |