Color Objects

I l @ ve RuBoard

Color Objects

You can use ActionScript to change the color of a movie clip. The easiest way to do this is to use the setRGB command. However, you cannot apply this directly to the movie clip instance. Instead, you first ask Flash for a reference to the movie clip's Color object. Do this with a new Color() function. Then you can use setRGB to set the color.

Here is a simple example. A reference to the color of the movie clip circle is placed in the variable circleColor . Then, the setRGB command changes this color to 0xFF0000, which is the hexidecimal value for red.

 circleColor = new Color("circle"); circleColor.setRGB(0xFF0000); 

You can also get the color of a movie clip. This is usually just 0 (0x000000 or "000000"). But if you use the Advanced Effect dialog to change it, you can get a different value. Figure 12.1 shows the Advanced Effect dialog.

Figure 12.1. The Advanced Effect color settings dialog allows you to modify the color and transparency of a movie clip. It corresponds to capabilities of the setTransform ActionScript command.


You use getRGB to get the color of a movie clip. However, this needs a toString(16) function to convert it to the hexadecimal value. The toString(16) tells it to convert the number to a string in base 16 rather than base 10:

 circleColor = new Color("circle"); trace(circleColor.getRGB(0xFF0000).toString(16)); 

There is another way to change the color of a movie clip. You can create a color transform object that corresponds to the eight entries shown in Figure 12.1.

To do this, first make a standard custom variable object. Then, assign to it the properties ra , ga , ba , aa , rb , gb , bb , and ab . These correspond to the eight entries in Figure 12.1. The first letters ” r, b, g and a ”refer to red, green, blue, and alpha. The second letters ” a and b ”refer to the left and right columns .

Then, instead of using setRGB , use setTransform , with this object as the parameter. Here is an example:

 circleColor = new Color("circle"); myObject = new Object(); myObject = {ra:100, rb:255, ga:0, gb:0, ba:0, bb: 0, aa: 100, ab: 0}; circleColor.setTransform(myObject); 

The setTransform command gives you pretty much complete control over the color of a movie clip.

I l @ ve RuBoard

Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272 © 2008-2017.
If you may any questions please contact us: