Colors can be described in a variety of ways. The primary way we express them in Flash is in terms of RGB (Red, Green and Blue). This is fine when you are working with known static values because we can express RGB in a single hexadecimal number. But it's not a real intuitive system. It's not real obvious that 0xD5BCE9 is a soft purplish blue or that 0xF64949 is a vibrant red color.
An alternative way of expressing colors is in terms of the Hue, Luminance and Saturation (HLS). Hue can be thought of much like a color wheel starting with red at 0 degrees and ranging through the visible spectrum back to red at 360 degrees. Luminance and Saturation are simply percentages representing the brightness (or darkness) of the color and the degree of vibrancy of the color respectively. A color with a low luminance will be very dark, a medium luminance will be very true to the base color and a high luminance will be very light. A low saturation will make the color grayer, while a high saturation will become increasingly true to the color represented in the hue.
So, instead of saying that our vibrant red color from above should be 0xF64949 we could say that it has a hue of 0, a luminance of 63% and a saturation of 90%. Suppose we wanted to contrast this color red with an equally bright and vibrant shade of orange. In RGB, it would be really awkward to figure out the values that would represent an equally bright and vibrant shade of orange. But in HLS, all you have to do is adjust the hue to 33 degrees and you're done with your calculations. A hue of 33, luminance of 63% and saturation of 90% gives you 0xF5A94B, or an equally bright and vibrant orange color.
To see the interaction between RGB and HLS, I made the application below. As you adjust the values of the sliders, the corresponding sliders will adjust to represent the color in RGB or HLS.
This is all well and good, but Flash's Color object doesn't have any support for describing a color in terms of HLS. And doing the conversion to and from RGB to HLS is quite complicated. However, there are a number of class libraries written in a variety of languages feely available on the Internet. Steve McMahon wrote a great HLS to RGB class in C#. Based on his work, I ported the class into ActionScript 2.0 and then used that class to create a custom color class (called SatoriColor) that supports both RGB and HLS. You can download the classes and two sample applications here.
You'll need to have both classes that are included in the zip file in a folder called SatoriInteractive for the classes to work. Once imported, the SatoriColor class can be instanced and used just like the native Flash Color object. Such as:
setRGB, getRGB, setTransform and getTransform work the same as the native Flash Color object. Two new methods (setHLS and getHLS) provide HLS support and three properties (hue, luminance and saturation) can be both read and written to.
The easiest way to work with this class is to use the three properties(hue, luminance and saturation). If you want to change the hue of a color, set the hue property to a new value between 0 and 360. If you want to affect the luminance or saturation, you can set those properties to a decimal value between 0 and 1 representing the percentage of luminance or saturation that you desire. The class will automatically convert the HLS data into RGB and update the color object appropriately.
An alternative way to adjust the SatoriColor with HLS is to use the setHLS method. setHLS takes in one argument (an object with values for h, l and s). An example of its usage:
getHLS will return an object with the properties h, l and s (just like the type of object used for the setHLS method).
It's really pretty simple, and makes creating dynamic run-time themes and skins much easier to envision and implement. Included in the source code for the SatoriColor class is the HLSRGB class that I ported from Steve McMahon's C# class. For more information on the HLSRGB class included with the source files, see my post at HeavyFlash.com. Full dictionary style documentation of the SatoriColor class is available at ActionScriptReference.com.