【发布时间】:2011-07-01 07:45:34
【问题描述】:
我是否可以限制每行文本区域的内容?
例如,如果用户粘贴的文本超出“预定义”行数,则文本区域将仅显示内容,直到先前设置的限制值。请记住,应该计算空行。
欢迎任何帮助。
非常感谢
【问题讨论】:
标签: apache-flex actionscript flex-spark
我是否可以限制每行文本区域的内容?
例如,如果用户粘贴的文本超出“预定义”行数,则文本区域将仅显示内容,直到先前设置的限制值。请记住,应该计算空行。
欢迎任何帮助。
非常感谢
【问题讨论】:
标签: apache-flex actionscript flex-spark
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<s:Application name="Spark_TextArea_limit_lines"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private const MAX_LINES:uint = 5;
private function textChangeHandler(event:Event):void {
//Split the string into an array of lines
var lines:Array = textArea.text.split("\n");
//If there are too many lines...
if (lines.length > MAX_LINES) {
//Clear the existing text
textArea.text = "";
//Then insert MAX_LINES of the previous text
for (var i:uint=0; i<MAX_LINES; i++) {
textArea.text += lines[i] + "\n";
}
//Finally, move the cursor to the end of input, as
//it is reset to position 0 when the text is modified.
textArea.selectRange(textArea.text.length, textArea.text.length);
}
}
]]>
</fx:Script>
<s:TextArea id="textArea" change="textChangeHandler(event)"/>
</s:Application>
【讨论】:
它适用于\r
var lines:Array = textArea.text.split("\r");
【讨论】: