Making <p> and <br> Tags Work with htmlText in ActionScript 3.0

I had one hell of a time trying to figure out why my paragraph breaks (<p>) and line breaks (<br>) were not working when I was using htmlText in Flash CS3 with ActionScript 3.0. All of the other HTML tags that are allowed by Flash worked fine, but those two break tags just would do anything. I had created a TextField variable called “info” and all the code checked out but there was one very important thing that I needed to put in place before it would all work the way I needed it to.
Here is the code that wouldn’t work:

var info:TextField = new TextField();
info.htmlText = "First line. 
Second line.
Third line."; addChild(info);

Here is what is should have looked like:

var info:TextField = new TextField();
info.multiline = true;
info.htmlText = "First line. 
Second line.
Third line."; addChild(info);

Why wasn’t my original code working? Well, to make sure that the HTML tags for paragraph breaks and line breaks would function properly, I needed to set the TextField’s multiline parameter to “true”. Just one tiny line of code and then everything worked perfectly. I hate it when that happens!

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie