Actionscript 3 Designer Toolkit

More design, less programming

Actionscript 3 Designer Toolkit header image 2

Displaying HTML formatted text: HTMLText Class

September 10th, 2009 · 1 Comment · AS3 Custom Classes

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 &amp;lt;font color=#FF0000&amp;gt;stage&amp;lt;/font&amp;gt;...' );
centerText.x =  0;
centerText.y = 24;
addChild( centerText );
 
// bottom right justified instance
var rightText:HTMLText = new HTMLText( 400, 'Verdana', 16, 0x333333, 'RIGHT', '&amp;lt;i&amp;gt;All&amp;lt;/i&amp;gt; the world is a &amp;lt;font color=#0033CC&amp;gt;stage&amp;lt;/font&amp;gt;...' );
rightText.x =  0;
rightText.y = 48;
addChild( rightText );

Below is the text generated by the code above.

[Download files: HTMLText.zip (70)

Post to Twitter

Tags: ·

One Comment so far ↓

Leave a Comment

Spam Protection by WP-SpamFree