Server-side carriage returns (\n) and dealing with them in flash (XML)
If you are receiving text from a server-side script such as PHP, ASP etc which has new line formatting using \n and these are being displayed
e.g,
Hello,\nThis is on a line under hello.is being displayed but should actually be displayed as:
Hello, This is on a line under hello.
It appears that Flash is actually escaping the \n character with another slash - as \\n
There are two fixes for this, one in flash and the other from the server-side.- Flash way:
function addNewLines(text:String) { return text.split("\\n").join("\n"); } // and call the function like so: var wrongText = ‘Hello,\nThis is on a line under hello.’; var output = addNewLines(wrongText); - Server-side way
Globally replace all \n characters with
(ampisand hash 10 semi-colon) -
It will then correctly display new lines when displayed in flash.


