HTML/CSS Service

Determining the number of lines in a TextArea control in Flex

Category: Flex Examples, Learn Flex    |    2,339 views

The following example shows how you can get the number of lines in a Flex TextArea control by using the getTextField() method (in the mx_internal namespace) and the numLines property.

Full code after the jump.

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”vertical”
verticalAlign=”middle”
backgroundColor=”white”>

<mx:Script>
<![CDATA[
import mx.utils.StringUtil;

private function textArea_change(evt:Event):void {
callLater(updateStats, [evt]);
}

private function updateStats(evt:Event):void {
var nLines:uint = textArea.mx_internal::getTextField().numLines;
var nChars:uint = textArea.length;
var str:String = “{0} characters; {1} lines”;
panel.status = StringUtil.substitute(str,
nChars,
nLines);
}
]]>
</mx:Script>

<mx:String id=”str” source=”lorem.txt” />

<mx:ApplicationControlBar dock=”true”>
<mx:Form styleName=”plain”>
<mx:FormItem label=”width (%):”>
<mx:HSlider id=”slider”
minimum=”50″
maximum=”100″
value=”100″
liveDragging=”true”
snapInterval=”1″
tickInterval=”10″ />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>

<mx:Panel id=”panel”
percentWidth=”{slider.value}”
height=”100%”>
<mx:TextArea id=”textArea”
htmlText=”{str}”
condenseWhite=”true”
width=”100%”
height=”100%”
change=”textArea_change(event);”
resize=”textArea_change(event);” />
</mx:Panel>

</mx:Application>

is enabled in the following example.

Share/Save/Bookmark

1 Star2 Stars

Tags:

2 responses so far!

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word