Using styles with the Label

You can set style properties to change the appearance of a label instance. All text in a Label component instance must share the same style. The Label component has a textFormat style, which has the same attributes as the TextFormat object and allows you to set the same properties for the content of Label.text as you can for a regular Flash TextField. The following example sets the color of text in a label to red.

To change the color of a label's text:

  1. Drag the Label component from the Components panel to the Stage and give it an instance name of a_label.
  2. Click the Parameters tab and replace the value of the text property with the text:

    Color me red

  3. Select Frame 1 in the main Timeline, open the Actions panel, and enter the following code:
    /* Create a new TextFormat object, which allows you to set multiple text properties at a time. */
    
    var tf:TextFormat = new TextFormat();
    tf.color = 0xFF0000;
    /* Apply this specific text format (red text) to the Label instance. */
    a_label.setStyle("textFormat", tf);
    
  4. Select Control > Test Movie.

For more information about Label styles, see the Label class in the ActionScript 3.0 Language and Components Reference.