Bottom Align Text Flash AS2

Getting Flash to display dynamic text the way you want it displayed can sometimes be a chore. Recently I had the need to bottom-align a dynamic text field that could vary between 1 and 3 lines high.

cdl_capture_2011-06-22-12_ 000

Here’s an example: Download source

The solution is pretty simple. The following code handles everything:


bottomCoord = text_txt._y + text_txt._height;
text_txt.autoSize = "center";

btn.onRelease=function() {
	text_txt.text = input_txt.text;
	text_txt._y = bottomCoord - text_txt._height;
}

First I record the bottom _y coordinate of the dynamic text field. Then I set the text field’s autosize property to ‘center’ allowing the field to dynamically expand and contract vertically. And finally, I adjust the text field’s _y position based on the new height.

http://rabidgadfly.com/2007/03/bottom-align-variable-length-text-fields-in-flash/

Leave a comment