O'Reilly logo

Learning ActionScript 3.0 by Zevan Rosser, Rich Shupe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Color Effects

There are multiple ways to apply color effects using ActionScript, and we will focus on three. The first is a relatively straightforward way of altering the emphasis of individual color channels in an image using the ColorTransform class. The second is a more powerful technique that uses the ColorMatrixFilter to apply a detailed matrix to simultaneously affect change to all color channels and alpha, which we will use to desaturate an image. The last method discussed is the simplest, using the static Color class to apply a tint to a display object.

ColorTransform

The ColorTransform class can be used to easily adjust individual color and alpha channels of a display object or BitmapData object. We will focus exclusively on color in the examples that follow, and use the class to invert an image (create a color negative), and apply a simple saturation effect.

The class offers two ways to change color. First, you can multiply a color channel by a fraction to increase or decrease its effect. For example, you can double the weight of the color by using a value of 2, and you can reduce the weight of the color in half by using 0.5 as a multiplier. Second, you can offset a color channel from −255 to 255 after the multiplier is applied. For example, assuming a default multiplier of 1, an offset value of 255 would maximize the red channel, 0 would apply no change, and −255 would remove all red from the image.

The following exercise manipulates three hypothetical movie clips instantiated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required