The HTMLText class renders a single line of HTML formatted text. Parameters controlled include font family, size, color, left/center/right alignment and changes to the text from HTML tags embedded within the text.
In the code below 3 instances of the HTMLText class are created; all have a width of 400 px, Verdana font, 16px font size, text is dark gray and each displays the same text phrase. The top instance, leftText, is left justified, the middle instance is centered and the bottom instance right justified. Also, HTML tags in the text affect the attributes of individual words.
import com.dtk.HTMLText; // top left justified instance var leftText:HTMLText = new HTMLText( 400, 'Verdana', 16, 0x333333, 'LEFT', 'All the world is a stage...' ); leftText.x = 0; leftText.y = 0; addChild( leftText ); // middle center justified instance var centerText:HTMLText = new HTMLText( 400, 'Verdana', 16, 0x333333, 'CENTER', "<strong>"All"</b>" the world is a &lt;font color=#FF0000&gt;stage&lt;/font&gt;...' ); centerText.x = 0; centerText.y = 24; addChild( centerText ); // bottom right justified instance var rightText:HTMLText = new HTMLText( 400, 'Verdana', 16, 0x333333, 'RIGHT', '&lt;i&gt;All&lt;/i&gt; the world is a &lt;font color=#0033CC&gt;stage&lt;/font&gt;...' ); rightText.x = 0; rightText.y = 48; addChild( rightText ); |
Below is the text generated by the code above.
[Download files: HTMLText.zip (70)
Wow, very cool. Thank you!