Table of Contents

TextField.textHeight Property Flash 6

pixel height of all the text in the text field read-only
theField.textHeight

Description

The integer textHeight property indicates the pixel height of the entire body of text contained by theField. It is not a measurement of the text currently displayed on screen in theField's bounding box; rather, it is a measurement of every character in theField.text, including those characters that can be accessed only by vertical scrolling. For each line of text, the textHeight property adds the height specified by the font metrics of the largest character on the line, including ascenders and descenders, whether or not the character in question has an ascender or a descender or is in upper- or lowercase. Note that textHeight is measured in pixels, not the number of lines or the page size (see the page size calculation in the Example under TextField.bottomScroll).

For example, in 12-point Times New Roman:

(Note: the font metrics listed here for Times New Roman are for one particular system; they may vary by platform.)

When the autoSize property is true, textHeight is always 4 pixels less than _height, leaving a small gutter between theField's top and bottom borders and the displayed characters.

To determine the height of a string before assigning it to a text field, use TextFormat.getTextExtent( ).

Example

The following simplified scrollbar code scales a scrollbar handle in proportion to the amount of overflow in a text field. Every time the field is scrolled, the code checks the ratio of _height to textHeight to determine the scale of the handle. It positions the handle based on the scroll and maxscroll properties. To try the code, first make two rectangular movie clips named scrollbg and scrollhandle.

// Create a multiline text field
this.createTextField("theField_txt", 1, 0, 0, 150, 40);
theField_txt.border = true;
theField_txt.text = "Line one \nLine two \nLine three \nLine four";
// Allow user input on multiple lines
theField_txt.type = "input";
theField_txt.multiline = true;
// Size the scrollbar background
scrollbg._width = 20;
scrollbg._height = theField_txt._height;
// Position the scrollbar background
scrollbg._x = theField_txt._x + theField_txt._width;
scrollbg._y = theField_txt._y;
// Size and position the scrollbar handle whenever the field is scrolled
theField_txt.onScroller = function () {
  // Size the scrollbar handle
  scrollhandle._width = 20;
  scrollhandle._height = theField_txt._height
                       * (theField_txt._height / theField_txt.textHeight);
  // Position the scrollbar handle
  scrollhandle._x = theField_txt._x + theField_txt._width;
  var trackSize = scrollbg._height - scrollhandle._height;
  scrollhandle._y = theField_txt._y
                  + trackSize * ((this.scroll-1)  / (this.maxscroll-1));
}
// Set the initial position of the scrollbar handle
theField_txt.onScroller();

See Also

TextField.autoSize, TextField._height, TextField.maxscroll, TextField.onScroller( ), TextField.scroll, TextField.textWidth, TextField._width, TextFormat.getTextExtent( ); the FScrollBar component in Appendix G


Table of Contents