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.