O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.17. Formatting User-Input Text

Problem

You want to apply formatting to text as it is entered into a text field by the user.

Solution

Apply a TextFormat object using the setNewTextFormat( ) method of the text field.

Discussion

You should use the setNewTextFormat( ) method of a text field object to apply text formatting to text as it is entered by the user. You should create a TextFormat object as in Recipe 8.16 and then pass that object to the text field’s setNewTextFormat( ) method:

myTextFormat = new TextFormat(  );
myTextFormat.color = 0x0000FF;      // Make the text blue.
myTextField.setNewTextFormat(myTextFormat);

When you use setNewTextFormat( ), the formatting is applied to text that the user types into the field.

See Also

Recipe 8.18

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required