Hi guys,
I’ve been trying to figure out a way to use html formatting inside an xml document and have accomplished it, but the only problem is that undefined is displayed before the text???
So the final result when I test the flash file is:
undefinedThis is bold text
How it works is the html tags in the xml document are written using the [ brackets instead. The function searches through the selected node(s) and converts the [] to <>
Heres the code:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]function[/COLOR] xmlTagsCOLOR=#000000[/COLOR]
[COLOR=#000000]{[/COLOR]
[COLOR=#000000]var[/COLOR] i;
[COLOR=#000000]var[/COLOR] contents;
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i = [COLOR=#000080]0[/COLOR]; i < [COLOR=#0000ff]xml[/COLOR].[COLOR=#0000ff]length[/COLOR]; i++[COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR]
tags = [COLOR=#0000ff]xml[/COLOR].[COLOR=#0000ff]charAt[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]tags == [COLOR=#ff0000]"["[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR]
tags = [COLOR=#ff0000]"<"[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]else[/COLOR] [COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR]tags == [COLOR=#ff0000]"]"[/COLOR][COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR]
tags = [COLOR=#ff0000]">"[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#808080]// end if[/COLOR]
contents = contents + tags;
[COLOR=#000000]}[/COLOR] [COLOR=#808080]// end of for[/COLOR]
[COLOR=#0000ff]return[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#808080]// End of the function[/COLOR]
[COLOR=#000000]function[/COLOR] loadXMLCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
loadXML = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]firstChild[/COLOR];
title = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];
total = loadXML.[COLOR=#0000ff]childNodes[/COLOR].[COLOR=#0000ff]length[/COLOR]
p = [COLOR=#000080]0[/COLOR];
[COLOR=#0000ff]for[/COLOR] [COLOR=#000000]([/COLOR]i=[COLOR=#000080]0[/COLOR]; i<total; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
title[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = xmlTags[COLOR=#000000]([/COLOR]loadXML.[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000ff]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]firstChild[/COLOR].[COLOR=#0000ff]nodeValue[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
words[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#0000ff]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#0000ff]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#ff0000]"xml document failed to load"[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]function[/COLOR] wordsCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
title_txt.[COLOR=#0000ff]htmlText[/COLOR] = title[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR];
[COLOR=#000000]}[/COLOR]
xmlData = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]XML[/COLOR]COLOR=#000000[/COLOR];
xmlData.[COLOR=#0000ff]ignoreWhite[/COLOR] = [COLOR=#000000]true[/COLOR];
xmlData.[COLOR=#0000ff]onLoad[/COLOR] = loadXML;
xmlData.[COLOR=#0000ff]load[/COLOR]COLOR=#000000[/COLOR];
[/LEFT]
[/FONT]
Heres the xml document:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<stuff>
<things>
<words>[ b ]This is bold text[ /b ]</words>
</things>
</stuff>
The spaces between the [] are there so the “this is bold text” won’t actually go bold on the forum, there are no spaces in the original xml document.
Cheers,
-Inept