Internet Explorer 6 is not supported.
Upgrade to view this site.

Colors and Numbers

Posted on February 18, 2008 at 8:11 pm

There are 2 classes that deal with color. There is the appropriately named Color class and the ColorTransform class. Color is a subclass of the ColorTransform class. The Color class adds a few more features to the ColorTransform class such as control over brightness and tint.

A new instance of the ColorTransform accepts a lot of parameters. There is redMultiplier, redOffset, greenMultiplier, greenOffset, blueMultiplier, blueOffset, alphaMultiplier and alphaOffset. Personally, I find these values very counterintuitive. Give me good old HSB any day. All these crazy, meaningless numbers are additive, which means they are appended to the target’s current color value. If you have an exact color value in mind you can circumvent trying to figure out how to use all this stuff with the color property. The color property can be used with the Color class and the ColorTransform class. Below are simple examples of the usage of this.

1
2
3
4
5
6
7
8
9
//using color transform
var myColorTransform:ColorTransform = new ColorTransform();
myColorTransform.color = 0xFF0000;
my_mc.transform.colorTransform = myColorTransform;
 
//using color
var myColor:Color = new Color();
myColor.color = 0xFF0000;
my_mc.transform.colorTransform = myColor;

With this technique you can use an unsigned integer, which may look familiar to web designers because it commonly used in web safe colors. Flash’s color palette uses these numbers, so it is easy to make a color in Flash’s GUI and take these numbers to the Actions panel.

If you need to make a transformation with the Multipliers and Offsets, there is a place in Flash where you can visually get these values. When you have a Movie Clip selected in the properties window go to Color > Advanced. Click on settings, there is a dialogue with all the same parameters as in the ColorTransform constructor function. In this dialogue the multipliers are a percentage. The percentage here is written as a value from 1 to -1 in Actionscript. So pretty much add a decimal point. The Offsets to the right in the dialogue remain the same. This way you can visually get the colors right and plug those numbers in the code.

1
2
3
//color transformation from white movie clip to purple
var myColorTransform:ColorTransform = new ColorTransform(.45, -.28, .87, 1, -28, 143, -38, 0);
my_mc.transform.colorTransform = myColorTransform;

The result of this code is purple assuming the Movie Clip started out as white. Change the color of the symbol on the timeline and you’ll see that the resulting color is different. This goes back to the point that this process is additive. So make sure that the starting color is the color that you really want before taking the time to copy down and write the 800 numbers needed to change a color.

Leave a Comment

*Required fields. Email will not be published.