TextField multiline + wrap get text height

20,931

Solution 1

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

Solution 2

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);
Share:
20,931
Lahey
Author by

Lahey

Updated on October 14, 2020

Comments

  • Lahey
    Lahey over 3 years

    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?