Question

When I add a TextField on my stage in my Flash project, I have to choose the size (width and height) of the field. If, with programming, I modify that text, I would like that TextField to resize and have the height it needs.

In particular, I am developing a chat application and I would like to wrap every message with typical bubble, but the length of that message may be whatever. In HTML it would be very easy, for example.

How can I do it?

Was it helpful?

Solution

You can just set the autoSize property of the TextField

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#autoSize

For Example:

myTextField.autoSize = "left"

If autoSize is set to TextFieldAutoSize.LEFT, the text is treated as left-justified text, meaning that the left margin of the text field remains fixed and any resizing of a single line of the text field is on the right margin. If the text includes a line break (for example, "\n" or "\r"), the bottom is also resized to fit the next line of text.

OTHER TIPS

For more accurate width/height detection use TextLineMetrics

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top