Using the color matrix filter
The ColorMatrixFilter class lets you apply a 4 x 5 matrix transformation on the ARGB color
and alpha values of every pixel on the input image to produce a result with a new set of ARGB
color and alpha values. This filter allows hue (distinct color or shade) rotation, saturation
(intensity of a specific hue) changes, luminance (brightness or intensity of a color) to alpha,
and various other effects. Also, you can animate these filters to create effects in your
applications.
You can apply the color matrix filter to bitmaps and movie clip instances.
For more information on the color matrix filter, see ColorMatrixFilter
(flash.filters.ColorMatrixFilter) in the ActionScript 2.0 Language Reference.
You can use the color matrix filter to modify the brightness of an instance, as the following
example demonstrates.
To increase the brightness of a movie clip:
1.
Create a new Flash document and save it as brightness.fla.
2.
Add the following ActionScript to Frame 1 of the Timeline:
import flash.filters.ColorMatrixFilter;
System.security.allowDomain("http://www.helpexamples.com/");
var mcl_obj:Object = new Object();
mcl_obj.onLoadInit = function(target_mc:MovieClip):Void {
var myElements_array:Array = [1, 0, 0, 0, 100,
0, 1, 0, 0, 100,
0, 0, 1, 0, 100,
0, 0, 0, 1, 0];
var myColorMatrix_filter:ColorMatrixFilter = new
ColorMatrixFilter(myElements_array);
target_mc.filters = [myColorMatrix_filter];
}
this.createEmptyMovieClip("img_mc", this.getNextHighestDepth());
var img_mcl:MovieClipLoader = new MovieClipLoader();
img_mcl.addListener(mcl_obj);
img_mcl.loadClip("http://www.helpexamples.com/flash/images/image2.jpg",
img_mc);
This code dynamically loads a JPEG image by using a MovieClipLoader instance. After
the image is completely loaded and is placed on the Stage, the instance's brightness is set to
100% by using a color matrix filter.
3.
Select Control > Test Movie to test the document.
Working with filters using ActionScript
525
Need help?
Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?