The following example shows how you can control the number of characters a user can type into a Flash ActionScript 3.0 TextInput control by setting the maxChars property.
Full code after the jump.
// ActionScript 3.0 /* Requires: * - TextInput component in Flash library */ import fl.controls.TextInput; var textInput:TextInput = new TextInput(); textInput.maxChars = 5; textInput.move(10, 10); addChild(textInput);
{ 2 comments… read them below or add one }
Hi Peter,
There is a way to restrict the max number of characters in a dynamic text field?
I’m loading a text from a data base, but in some cases the text is larger than the Dynamic Text Field and this made the text field scrollable and I don’t want that, I could make the Text Field not selectable, but I want it to be selectable.
May be is property I’m missing… an scrollable property or something
Thanks!
Daniel Rodriguez,
As far as I know there isn’t a way to make text selectable, but not cause scrolling in a text field. The
maxCharsproperty only applies when a user is typing content in, it doesn’t apply when you set the text using ActionScript.You could try trimming the content to a certain number of characters by using the
substr()orsubstring()methods:Peter