Copy link to clipboard
Copied
Hi everyone!
I have a problem regarding text boxs.
Lets say I created a text box, and I want to limit the number of input characters\numbers to 3, how can I do that?
Alternatively, can I make that size of the text box change (expand) during input so the text doesnt "disappear" while exiting the borders of the text box? (Assuming that even possible)...
If anyone can write the code, or refer me to the relevant part in the manual (I didn't fint it) I'll be greatful.
Thank you!
Copy link to clipboard
Copied
Hi,
I do not have idea about dynamically change the width of text box but for limit the number of characters you can use this :
public var txtName:TextField;
public function test():void
{
txtName = new TextField();
txtName.maxChars = 3;
}
Vipul
Copy link to clipboard
Copied
Thanks!
Thats one down, one to go
Copy link to clipboard
Copied
There are a couple of ways I can think of to approach changing the width of the input textfield ("it" below).
One is to just use the autoSize property...
it.autoSize = TextFieldAutoSize.LEFT;
and the other is to adjust the width based on the width of the text inside the textfield....
it.addEventListener(Event.CHANGE, resizeIT);
function resizeIT(evt:Event){
it.width = it.textWidth;
}
Copy link to clipboard
Copied
Hi Ned, thank you for answering!
I have a question regarding the first method-if I already created a text box on the stage, can I apply it for that text box?
Cause' right now I'm getting for that line:
1120: Access of undefined property TextFieldAutoSize.
Or I must define the that box by code?
Thank you!
Copy link to clipboard
Copied
Yes, you can apply it to a textfield that you place on the stage. How did you write the code?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now