Coloring HTML Text in Flash (Actionscript 3 quick code note)

Just figured I’d post this real fast. Its not much code, but I’ve been color coding a lot of htmlText in Flash this week and coincidently just got an email about doing so…

var urlLinkColor:String = “CC4477”;
var textToColor:String = “Rules”;
var myTextVar:String = “CartoonSmart <font color=\u0022#” + urlLinkColor +”\u0022>” + textToColor + “</font>”;
myTextField.htmlText = myTextVar;
//myTextField  (already onstage) would now say “CartoonSmart rules” with rules colored differently

var urlLinkColor:String = “CC4477”;

var textToColor:String = “Rules”;

var myTextVar:String = “CartoonSmart <font color=\u0022#” + urlLinkColor +”\u0022>” + textToColor + “</font>”;

myTextField.htmlText = myTextVar;

//myTextField  (already onstage) would now say “CartoonSmart rules” with rules colored differently

Make sense? The big thing to remember is to make sure that myTextField uses the .htmlText property instead of just .text . Then those font tags get rendered. And whats with the \u0022 ?? That makes a Quote symbol. So this line…

var myTextVar:String = “CartoonSmart <font color=\u0022#” + urlLinkColor +”\u0022>” + textToColor + “</font>”;

… is really just….

var myTextVar:String = “CartoonSmart <font color=”CC4477″> rules </font>”;

Published you should see…

Color coding HTML text in Flash (actionscript 3)

Advertisements

6 thoughts on “Coloring HTML Text in Flash (Actionscript 3 quick code note)

  1. This is very cute, yet the HTML reading in ActionScript 3.0 is still limited. It will not accept some tags as header tags for example, and although linking to CSS is possible, it is yet far from user friendly. It is great for linking and above all… is better then nothing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s