3.5. Tinting a Movie Clip’s Color

Problem

You want to modify the color tint of a movie clip (as opposed to applying a single color to the whole shape).

Solution

Use the setTransform( ) method of the Color object that targets the movie clip.

Discussion

Using Color.setRGB( ) to fill a movie clip with a solid color overrides any color contrast within the movie clip. To apply a tint to a movie clip, use Color.setTransform( ) instead.

Flash records the color values set for a movie clip during authoring. A single clip might contain hundreds of colors. However, setRGB( ) applies the same RGB value to every color region within a movie clip. On the other hand, setTransform( ) can modify colors relative to their original values. For example, consider a movie clip that contains a JPEG with hundreds of colors. Using setRGB( ) applies one color to the whole movie clip, resulting in a solid-colored rectangle. But with setTransform( ), you can adjust the red, green, and blue levels of each original color, effectively tinting the image without losing the initial contrast.

The setTransform( ) method accepts a single parameter: a transform object that includes the eight properties shown in Table 3-1.

Table 3-1. Properties of a color transform object

Property

Range

Description

ra

-100 to 100

Red percentage transformation

rb

-255 to 255

Red offset

ga

-100 to 100

Green percentage transformation

gb

-255 to 255

Green offset

ba

-100 to 100

Blue percentage transformation

bb

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.