views:

65

answers:

1

I would like to set a fixed width for an input textfield with an embedded font. I would like to have the option to left-, right-, or center-justify the text. This is proving difficult.

If I set myTextField.autoSize = TextFieldAutoSize.LEFT;, I get left-justified text, but the textfield width changes with each keystroke. Same trade-off with TextFieldAutoSize.RIGHT and TextFieldAutoSize.CENTER.

Now, if I use TextFieldAutoSize.NONE, then I can fix the width and height of my textfield, making it the size I want... but the cursor is always blinking in the middle of the textfield. What's the secret to justifying that cursor to the left [or right] and the textfield staying the size I initially set it to?

+1  A: 

You should use the TextFormat classes align property with the TextFormatAlign class for paragraph alignment. The TextField autoSize changed the bounding box size of the TextField.

So you would do something like:

myTextField.autoSize = TextFieldAutoSize.NONE; // This is the default anyway.
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.align = TextFormatAlign.LEFT;
myTextField.defaultTextFormat = myTextFormat;
TandemAdam