Skip to content Flash-fx website
flash-fx logo image1
flash-fx logo image2
Simple solutions to complex problems. Historical swordsmanship Great online resource and forums relating to Maya and 3D.
Home << Tutorials << Flash << Server-side carriage returns (\n) and dealing with them in flash (XML)

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
    &#10;
    (ampisand hash 10 semi-colon) -
    It will then correctly display new lines when displayed in flash.