Regular expressions for custom html support in AS3

This weekend I decided to take an in depth look at the options we have for formating text in AS3. Those three options being standard HTML, CSS, and TextFormat objects. In the past I have worked with all three types with disappointment. The text format options are the best on a whole, allowing for the most control and flexability, but difficult to control if your working with dynamic text. CSS is great for accomplishing styling determined externally and dynamic content, despite the fact of its limited implementation.

I came up with one intriguing idea that I felt was worth sharing, that being using regular expressions to parse text data and format HTML tags (or rather any tag) with text format objects. There are some benefits to this, mainly being the ability to offer a wider range of custom support. I’ve only done some basic proof of concept tests, (see below), but the possibilities are intriguing. One immediate concept that comes to mind is proper image tag support.

In a robust system tags could offer all kinds of support, for example button definitions, or ordered/unordered lists, nested lists, and custom bullet styling, and support for a wide range of html tags, such as H1, H2, ect.

Heres an example of it in use. Even though tags are applied to the fields, they don’t get stripped out since the text was applied using the standard .text rather than .htmlText.


AS3, Regex


Comment functionality has been disabled. Contact me on Twitter.

Ali Tan Ucer said:

This is interesting.

I am also using Rexp. to parse out or change html tags in order to show the HTML text properly. But again, we are still limited with how the Flash Text Field renders the HTML text. The new Text Engine (Flash 10) is far more complicated to implement good HTML rendering. But i am more willing to do that than try to reinvent the wheel with good old Text Field.

I am still interested in your idea though. How do you think you can implement button definitions or custom bullet styling??

Can you please give more examples?

Thanks Ali Tan Ucer


Browse All >