Auto resize box of input text
Copy link to clipboard
Copied
Hi, when adding an Input text for someone to write on it, I want the text box auto resize while they are typing, mainly when the user types Intro and the line moves up, but without dissappearing within the text box, but just resizing it.
Copy link to clipboard
Copied
Hi.
AS3 or HTML5 Canvas?
And can you give a visual example?
Regards,
JC
Copy link to clipboard
Copied
Hey!
- I'm working with AS3
- I need the text box to auto resize so I can read all the message without being cropped by the same text box (attached sample)
Copy link to clipboard
Copied
are you applying the autoSize property after/as text is entered?
Copy link to clipboard
Copied
No, how can I apply it?
Copy link to clipboard
Copied
use a textfield (eg, tf) listener to apply
tf.autoSize="left";
Copy link to clipboard
Copied
eg,
Copy link to clipboard
Copied
Hi.
According to the video attached, do you want to resize the text box vertically, right?
Please try something like this:
import flash.events.Event;
var initialTFHeight:Number = yourTF.height;
var tfBottomOffset:Number = 50; // make sure the last line will be visible
function resizeTFVertically(e:Event):void
{
// resize the text box according to the text height but clamping the value to a minimum
e.currentTarget.height = Math.max(e.currentTarget.textHeight + tfBottomOffset, initialTFHeight);
e.currentTarget.scrollV = 1;
}
yourTF.multiline = true; // set this value to true here or in the Properties panel
yourTF.addEventListener(Event.CHANGE, resizeTFVertically);
I hope this helps.
Regards,
JC

