Table of Contents

TextField.maxChars Property Flash 5

limits the allowed length of user inputFlash 6; accessible only via authoring tool in read/write
theField.maxChars

Description

Used with user-input text fields only, the integer maxChars property limits the amount of text a user can enter into a text field. It defaults to null, which allows an unlimited amount of text to be entered (as does the value 0). Positive settings allow the specified number of characters to be entered; negative settings disable text entry completely. The maxChars property does not limit text changes made via ActionScript. The text and htmlText properties can be set to any value despite maxChars limitations.

The maxChars property is often used with input forms that require a certain format for their data. For example, we can use it to limit a date entry to a two-digit day, a two-digit month, and a four-digit year. To further curtail text entry, we can use the TextField.restrict property, which specifies a set of allowed input characters for a text field.

Example

The following code limits the number of characters that can be entered into userName_txt to 15:

this.createTextField("userName_txt", 1, 0, 0, 200, 20);
userName_txt.type = "input";
userName_txt.text = "your name here";
userName_txt.maxChars = 15;

See Also

TextField.htmlText, TextField.restrict, TextField.text, TextField._width, String.charAt( ), String.length


Table of Contents