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

No credit card required

# 3.4. Setting the RGB Relative to Its Current Value

## Problem

You want to modify the RGB value of a movie clip relative to its current value.

## Solution

Use `Color.getRGB( )` to retrieve the current value, then perform bitwise operations to modify the value, and set the new value using `Color.setRGB( )`.

## Discussion

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 the `Color` object.
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 the `red`,
// `green`, and `blue` values 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 with `Color.setRGB(  )`.
rgb = (red << 16) | (green  << 8) | blue;
my_color.setRGB(rgb);```

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

No credit card required