Recipe 8.5. Limiting the Length of User InputProblemYou want to restrict the number of characters that a user can enter into an input text field or text input component instance. SolutionWith the text field selected, enter a nonzero numeric value in the Maximum Characters field of the Property inspector. Optionally, set the instance's maxChars property to a nonzero numeric value using ActionScript. Or, if you are using a text input component, set the maxChars parameter to a nonzero numeric value. DiscussionIn some scenarios, you want to restrict the number of characters that a user can type into an input field. For example, you may want to limit a user to five characters when entering a U.S. zip code. Flash lets you limit the length of the input for both input text fields and text input components. For an input text field, you can use the Maximum Characters option in the Property inspector (see Figure 8-2). Enter a nonzero numeric value while you have selected the input text field instance on the stage. A value of 0 allows the user to enter an unlimited number of characters. Figure 8-2. Use the Maximum Characters field to limit the number of characters that a user can enter into an input text fieldOptionally, you can use ActionScript to set the maximum number of characters by assigning a value to the instance's maxChars property. For example: tInputField.maxChars = 10; If you're using a text input component instance, you can set the instance's max-Chars parameter in the Component Inspector panel. A value of null or 0 allows the user to enter an unlimited number of characters. A nonzero numeric value allows the user to enter the corresponding number of characters. You can also restrict the allowed characters that a user can enter into an input text field. |
Tripod >> 3pod Tips & Learning and manuals for educations