474
Animation, Filters, and Drawings
Adding color and brightness effects with code
In addition to using ActionScript to set and animate alpha fades (see
“Fading objects with
code” on page 472
), you can animate various color and brightness effects by using code
instead of using the Filters panel in the Property inspector.
The following procedure loads a JPEG image and applies a color transform filter, which
modifies the red and green channels as the mouse pointer moves along the
x
-axis and
y
-axis.
To change an object’s color channels by using ActionScript:
1.
Create a new Flash document called
colorTrans.fla
.
2.
Select Frame 1 of the Timeline, and add the following code to the Actions panel:
import flash.geom.Transform;
import flash.geom.ColorTransform;
var imageClip:MovieClip = this.createEmptyMovieClip("imageClip", 1);
var clipLoader:MovieClipLoader = new MovieClipLoader();
clipLoader.loadClip("http://www.helpexamples.com/flash/images/
image1.jpg", imageClip);
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function():Void {
var transformer:Transform = new Transform(imageClip);
var colorTransformer:ColorTransform = transformer.colorTransform;
colorTransformer.redMultiplier = (_xmouse / Stage.width) * 1;
colorTransformer.greenMultiplier = (_ymouse / Stage.height) * 1;
transformer.colorTransform = colorTransformer;
}
Mouse.addListener(mouseListener);
3.
Select Control > Test Movie to test the document, and then move the mouse pointer
around the Stage.
The image file that loads transforms colors as you move the mouse.
You can also use the ColorMatrixFilter class to convert a color image to a black and white
image, as the following procedure shows.
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...