Skip to main content
Participating Frequently
January 5, 2024
Question

Auto resize box of input text

  • January 5, 2024
  • 2 replies
  • 468 views

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.

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 5, 2024

    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

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 5, 2024

    Hi.

     

    AS3 or HTML5 Canvas?

    And can you give a visual example?

    Regards,

    JC

    lumpandroAuthor
    Participating Frequently
    January 5, 2024

    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)

     

    lumpandroAuthor
    Participating Frequently
    January 5, 2024

    are you applying the autoSize property after/as text is entered?


    No, how can I apply it?