forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetFormattedText.as
More file actions
32 lines (30 loc) · 782 Bytes
/
setFormattedText.as
File metadata and controls
32 lines (30 loc) · 782 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
package utils.textField
{
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import utils.validation.isBlank;
/**
* Set the text of a <code>TextField</code> while preserving the formatting (leading, kerning, etc).
* XXX - Warning: htmlText and styles can break the formatting: no known fix as of yet.
*/
public function setFormattedText(tf:TextField, str:String, autoSize:Boolean = true):void
{
var s:String = (isBlank(str)) ? " " : str;
if (autoSize)
{
tf.autoSize = TextFieldAutoSize.LEFT;
}
var textFormat:TextFormat = tf.getTextFormat();
if (tf.type == TextFieldType.INPUT)
{
tf.text = s;
}
else
{
tf.htmlText = s;
}
tf.setTextFormat(textFormat);
}
}