Developer Guide
The displayAsPassword property simply hides the text (displaying it as a series of asterisks) as the user types it.
displayAsPassword is set to true, the Cut and Copy commands and their corresponding keyboard
shortcuts will not function. As the following example shows, you assign the
displayAsPassword property just as
you would other properties, such as background and color:
myTextBox.type = TextFieldType.INPUT;
myTextBox.background = true;
myTextBox.displayAsPassword = true;
The restrict property is a little more complicated since you need to specify what characters the user is allowed to
type in an input text field. You can allow specific letters, numbers, or ranges of letters, numbers, and characters. The
following code allows the user to enter only uppercase letters (and not numbers or special characters) in the text
myTextBox.restrict = “A-Z”;
ActionScript 3.0 uses hyphens to define ranges, and carets to define excluded characters. For more information about
defining what is restricted in an input text field, see the
flash.text.TextField.restrict property entry in the
ActionScript 3.0 Language and Components Reference.
Formatting text
You have several options for programmatically formatting the display of text. You can set properties directly on the
TextField instance—for example, the
TextFIeld.thickness, TextField.textColor, and
TextField.textHeight properties. Or you can designate the content of the text field using the htmlText property
and use the supported HTML tags, such as
b, i, and u. But you can also apply TextFormat objects to text fields
containing plain text, or StyleSheet objects to text fields containing the
htmlText property. Using TextFormat and
StyleSheet objects provides the most control and consistency over the appearance of text throughout your appli-
cation. You can define a TextFormat or StyleSheet object and apply it to many or all text fields in your application.
Assigning text formats
You can use the TextFormat class to set a number of different text display properties and to apply them to the entire
contents of a TextField object, or to a range of text.
The following example applies one TextFormat object to an entire TextField object and applies a second TextFormat
object to a range of text within that TextField object:
var tf:TextField = new TextField();
tf.text = "Hello Hello";
var format1:TextFormat = new TextFormat();
format1.color = 0xFF0000;
var format2:TextFormat = new TextFormat();
format2.font = "Courier";
var startRange:uint = 6;
tf.setTextFormat(format2, startRange);

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.