Vertical vertical alignment in the middle
6 answers
var parentContainer:DisplayObjectContainer = ...;
var textField:TextField = ...;
textField.autoSize = TextFieldAutoSize.CENTER;
// set width, height, wordWrap etc if needed
//after setting the text or in the textInput event handler if the
//textField is user editable
textField.y = parentContainer.height * 0.5 - textField.textHeight * 0.5;
+8
source to share
Only TLFTextField (a class in the fl.text package) has a built-in property to set the vertical alignment of text.
Check out http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/text/TLFTextField.html
+4
source to share
I had textboxes in the timeline in my situation, and they were already adjusted according to my needs (their size represented the alignment region) and set to Behavior: Multiline.
But I think that text boxes can be created and sorted using ActionScript.
So, I updated my textboxes with the following function:
function fitText(field:TextField, myString:String):void {
var initialHeight:Number = field.height;
field.autoSize = "center";//doesn't really affect the alignment, it just makes the texfield autosizeable.
field.multiline = true;
field.wordWrap = true;
field.text = myString;
field.y += (initialHeight - field.height) / 2;
}
0
source to share