Arslan
Arslan

Reputation: 43

Flex: Determining number of lines a spark text area can hold without overflowing

I want to implement paging in a spark text area. For that I want to find out the number of lines a spark textArea can hold before the scrollbars appear and just feed that much lines to the text area.

Upvotes: 1

Views: 2872

Answers (2)

pho
pho

Reputation: 25489

var numLines:int=t.heightInLines;

var numChars:int=t.widthInChars;

The documentation:

spark.components.TextArea.heightInLines():Number The default height of the control, measured in lines. The control's formatting styles, such as fontSize and lineHeight, are used to calculate the line height in pixels.

You would, for example, set this property to 5 if you want the height of the RichEditableText to be sufficient to display five lines of text.

If this property is NaN (the default), then the component's default height will be determined from the text to be displayed.

This property will be ignored if you specify an explicit height, a percent height, or both top and bottom constraints.

RichEditableText's measure() method uses widthInChars and heightInLines to determine the measuredWidth and measuredHeight. These are similar to the cols and rows of an HTML TextArea.

Since both widthInChars and heightInLines default to NaN, RichTextEditable "autosizes" by default: it starts out very small if it has no text, grows in width as you type, and grows in height when you press Enter to start a new line.

Upvotes: 0

puzzle-it
puzzle-it

Reputation: 46

The number of lines a TextArea can hold before a vertical ScrollBar appear is determinated by the heightInLines property.

The code

var number_of_lines:int=textArea.heightInLines;

will return inside the variable number_of_lines the number of lines you are looking for, and textArea is the id of the TextArea object you are checking.

Upvotes: 0

Related Questions