views:

36

answers:

2

I have a TextField with multiline and word wrap enabled, and a fixed width. I want to calculate the total height of the text inside it.

I tried using TextField.textHeight, but that gives me the height of one line. Because of the wrapping, I can't easily calculate the number of lines to multiply it with the line height. TextField.height just gives me the fixed, default height of the field, 100 pixels.

So how to do it?

A: 

There must be a mistake in your code, since textHeight should return your TextField height , not just one line height.

PatrickS
Well maybe I had something wrong in my code, it's ok now though. Can't really remember how or when I fixed it.
Lahaye
A: 

make sure you include wordWrap

this traces txt.textHeight = 135

var format:TextFormat = new TextFormat();
format.font = new Bauhaus ().fontName;

var txt:TextField = new TextField();
txt.embedFonts = true;
txt.multiline = true;
txt.defaultTextFormat = format;
txt.wordWrap = true;
txt.width = 100;
txt.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi metus diam, condimentum sagittis rutrum vitae, vehicula et velit.";
addChild(txt);

trace("txt.textHeight "+txt.textHeight);
daidai