Include your HTML tags inside XML for flash


As anybody familiar with XML HTML and Flash that XML can not take characters like <, >, &, " and ' it is possible to use a CDATA node to turn around it but a node value can not take CDATA so what could be a solution.

If you need to have some text coming from a database with html tags supported by Flash such as <b> for bold, <u> underline, <i> italic and others, you will face this problem for sure, I come with a small simple solution, a script replacement so that I can write inside the xml [b] [u] [i] to turn around this problem and here is the AS that can solve this problem:


Let's said we have a text like this :

var tex:String = "This is my text and this is a [b]bold[/b] word";

lets said that text come from an xml node as [ can be used in xml without problem to specify an HTML tag


in my AS code I separate the charachters "[" and "]" with split function, then I replace them with "<" and ">" with join function.


var1 = tex.split("[");

tex = var1.join("<");



var2 = tex.split("]");

tex = var2.join(">");


In my text field, I enable the html by

test_txt.html = true;

Then I point it to our tex text variable

test_txt.htmlText = tex;

Text will be changed to: This is my text and this is a <b>bold</b> word


Simple !!! isn't it :)))