Tabs and Linefeeds (Newlines) in XML driven TextFields

Man Flash can be annoying sometimes. So I’m showing some settings as a list, like
Item: value1
Item Two: value2
Item Three: value3

And the client asks if we can align the values vertically, and thinking like a programmer who likes to keep his code clean I’m thinking «Sure, that shouldn’t be a problem, I’ll just add some \t‘s to the XML file and we should be all set,» but all that comes out is, “Sure, should only take a few minutes to add.”

So I add some \t‘s to the XML and what does flash do with them, it prints out all literal backslashes and ts.

SO then what? Well I was being lazy and specifying xml.node not xml.node.text() to get the text values. Switching it does nothing. So then I start tracing things and looking around the Goog. Finally it becomes apparent that Flash is urlencoding the XML text in the background when processing it, and when it urldecodes it, some things are kept that shouldn’t be, like all escaped string characters that would normally not print.

Oh yeah, condenseWhite was false.

So I start with just doing a simple replace(/\\t/g, “!!!!”) to find out if I can even find the damn things, and I get no exclamation marks… or dirty words. Then a forum entry that was so buried I haven’t even found it again to link to, suggested using unescape(xml.node.text()) for a close, but ultimately unrelated problem.

To make a long story short here’s the solution:

	var tabs:RegExp = /\\t/g;
	var newlines:RegExp = /\\n/g;
	txt.htmlText = unescape(wagerText).replace(tabs, "\t").replace(newlines, "\n");

Go figure right?

As always if anyone has a better solution I’m all ears, or at least all comment-reading… eventually.