Table of Contents

TextFormat.color Property Flash 6

specifies character color read/write
theFormat.color

Description

The integer color property specifies the color of characters using RGB hexadecimal triplet notation�0xRRGGBB, where RR, GG, and BB are two-digit hex numbers representing Red, Green, and Blue. For example, the following sets color to red:

theFormat.color = 0xFF0000;

For a complete discussion of RGB triplet notation, see the Color class.

To set the color of an entire text field, invoke TextField.setTextFormat( ) without specifying any index arguments:

this.createTextField("theField_txt", 1, 0, 0, 200, 20);
theField_txt.border = true;
theField_txt.text = "Play with color."
// Create a TextFormat object
format = new TextFormat();
format.color = 0xFF0000;
// Make the whole field red
theField_txt.setTextFormat(format);

Alternatively, use the convenient TextField.textColor property directly on the field, without a TextFormat object:

theField_txt.textColor = 0xFF0000;

To set the color of a single character, apply the format with a single index argument:

theField_txt.setTextFormat(0, format); // Make the first character red

To set the color of a range of characters, apply the format with start and end index arguments:

theField_txt.setTextFormat(10, 15, format);  // Set red for characters 10,
                                             // 11, 12, 13, and 14 ("color")

The default color value (as contained in the TextFormat object returned by TextField.getTextFormat( )) for a text field that contains text is 0 (black). For a text field without any text, the color value is null. For a completely new TextFormat object, it is also null, indicating that color will not be set when the format is applied to a text field:

trace(anyUnformattedField_txt.getTextFormat().color);  // Displays: 0
var format = new TextFormat();
trace(format.color);                                   // Displays: "null"

See Also

The Color class , TextField.textColor


Table of Contents