15.5. Working with Color Styles

Problem

You want to apply a color style setting to a component or components.

Solution

Assign a value to the appropriate style using either a numeric value or one of the predefined color strings.

Discussion

There are a handful of styles that deal with color. Each of the color styles is discussed in slightly more detail in the appropriate recipe later in this chapter as they apply to specific components. However, regardless of which color style you are setting, you have two options for the value: one of the predefined color string values, or a numeric value (typically in hexadecimal format). The following color strings are recognized by Flash:

Color string

Hexadecimal value

Black

0x000000

Blue

0x0000FF

Cyan

0x00FFFF

Green

0x00FF00

Magenta

0xFF00FF

Red

0xFF0000

White

0xFFFFFF

Yellow

0xFFFF00

For example, if you want to apply a red value to the color style globally, you can use the following line of code:

	_global.style.setStyle("color", "red");

If you want to use a color value other than one of the predefined color strings, you can use numbers instead. Typically, you’ll work with the numbers in hexadecimal format. In ActionScript, hexadecimal numbers are prefixed with 0x. For example, the hexadecimal representation for red is 0xFF0000. The following line of code is, therefore, the equivalent to the previous example:

	_global.style.setStyles("color", 0xFF0000);

Unless you happen to already know the hexadecimal value for the colors you want to ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.