-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextHelper.as
37 lines (31 loc) · 1.02 KB
/
TextHelper.as
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
34
35
36
37
package toolbox
{
import flash.text.engine.*;
import flash.display.MovieClip;
/*
*
*/
public class TextHelper
{
public static function displayText( text:String, mcName:String, fontSize:Number = 16, xPos:Number = 15, yPos:Number = 20, lineWidth:Number = 300, color:uint = 0x000000 ):MovieClip {
var textMC:MovieClip = new MovieClip();
var fontDescription:FontDescription = new FontDescription("Georgia");
var format:ElementFormat = new ElementFormat(fontDescription);
format.fontSize = fontSize;
format.color = color;
var textElement:TextElement = new TextElement( text, format );
var textBlock:TextBlock = new TextBlock();
textBlock.content = textElement;
var textLine:TextLine = textBlock.createTextLine( null, lineWidth );
while( textLine ) {
textLine.x = xPos;
textLine.y = yPos;
yPos += textLine.height + 2;
textMC.addChild( textLine );
textLine = textBlock.createTextLine( textLine, lineWidth );
}
textMC.name = mcName;
return textMC;
}
}
}