July 2003
Intermediate to advanced
896 pages
45h 43m
English
You want to modify the RGB value of a movie clip relative to its current value.
Use Color.getRGB( ) to retrieve the current
value, then perform bitwise operations to modify the value, and set
the new value using Color.setRGB( ).
We saw in Recipe 3.3 how to retrieve the
current RGB value of a movie clip using Color.getRGB(
) and then use bitwise operations to extract the red,
blue, and green components. To perform a relative color adjustment,
simply modify the individual color components and reapply the new
color using Color.setRGB( ). For example, you
could brighten a movie clip’s color by increasing
the red, green, and blue components by a certain amount:
// Create theColorobject. my_color = new Color(myMovieClip); // Retrieve the current RGB setting. rgb = my_color.getRGB( ); red = (rgb >> 16); green = (rgb >> 8) & 0xFF; blue = rgb & 0xFF; // Brighten the colors by increasing their magnitude. This assumes that thered, //green, andbluevalues are no more than 245 prior to the operation. red += 10; green += 10; blue += 10; // Combine the components into a single RGB value and apply it withColor.setRGB( ). rgb = (red << 16) | (green << 8) | blue; my_color.setRGB(rgb);
Read now
Unlock full access