Trim TextField spaces and have perfect autosizing?

Hi all,

I’m trying to get a textfield going that will tart as a short rectangular textfield allowing user input, but that will resize to however much text they add or remove ( I haven’t figured out how to make it size down as well), and not start off with any extra white space.

I know I should be using trim or some other means of getting rid of white space, but I haven’t figured it out (along with how to automatically size down).

Here is the code for it so far:

class Main extends Sprite

public function new () 
    super ();

function createInputTextField():Void
    var tf:TextField = new TextField();
    tf.text = "abc";
    tf.type = TextFieldType.INPUT;
    tf.border = true;
	tf.x = (Lib.current.stage.stageWidth - tf.width) / 2;
	tf.y = 400;
	tf.autoSize = TextFieldAutoSize.CENTER;
    addChild( tf );


I just really need to know how to:

Trim text (I’ve tried some things like rtrim but I cant get anything to work and don’t know which method is appropriate)
Make TextField that grows and shrinks with the text being typed by the user.
Would be much appreciated :slight_smile:

Does StringTools.trim (text) help?