forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtruncateMultilineText.as
More file actions
33 lines (32 loc) · 926 Bytes
/
truncateMultilineText.as
File metadata and controls
33 lines (32 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package utils.textField
{
import flash.text.TextField;
/**
* Truncate a multiline <code>TextField</code> after the defined number of lines of text.
* @param tf <code>TextField</code> to truncate.
* @param numAlllowedLines before the remaining text is removed.
* @param isEllipsed determines whether the text is ended with "..." or not.
*/
public function truncateMultilineText(tf:TextField, numAlllowedLines:uint, isEllipsed:Boolean = true):void
{
if (tf.bottomScrollV > numAlllowedLines)
{
var len:int = tf.text.length;
for (var i:int = 0; i < len; i++)
{
tf.scrollV = tf.maxScrollV;
if (tf.bottomScrollV > numAlllowedLines)
{
tf.text = tf.text.slice(0, -1);
}
else
{
var e:int = (isEllipsed) ? -3 : tf.text.lastIndexOf(" ");
tf.text = tf.text.slice(0, e);
tf.appendText("...");
break;
}
}
}
}
}