
TextField.tabEnabled Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
870
|
ActionScript Language Reference
Here, using setTextFormat(), we first assign our text and then apply formatting to it:
// Create the text field
this.createTextField("title_txt", 1, 0, 0, 150, 40);
// Assign the field some text for display
title_txt.text = "What's New?";
// Now create and apply our TextFormat object
title_txt.setTextFormat(new TextFormat("Arial", 14, 0xFF0000));
If we mistakenly apply our format before the text is assigned, nothing happens:
// Oops! Wrong order...
title_txt.setTextFormat(new TextFormat("Arial", 14, 0xFF0000));
title_txt.text = "What's New?";
Conversely, when using setNewTextFormat(), we must be sure to apply our format before
assigning text to the text field:
title_txt.setNewTextFormat(new TextFormat("Arial", 14, 0xFF0000));
title_txt.text = "What's New?";
The setNewTextFormat() method is convenient when text is likely to change, because it
applies to all future assignments for the field:
// The text "Latest News" is still red, 14-point Arial.
title_txt.text = "Latest News";
For a detailed description of TextFormat objects, see the TextFormat class. Note that text
can also be formatted with HTML, as described under
TextField.html and TextField.
htmlText
.
Example
The following code adds to all TextField objects a rainbow() method ...