How to add a line break to a text coming from XML in Flash (AS2/AS3)?
I've been trying with \n and \r, and <br> using HTML text and it was breaking the XML; it could have been fixed with <![CDATA[ but I didn't like the solution, and in the end... I didn't want to use HTML text!
The answer was too easy, really:

This simple characters combination made it. Just put this inside your XML's texts to have a line break. Cool.
As many other times, I don't know why this is not advertised everywhere, it's the simplest and cleanest solution to add line breaks to a text field from XML.
Well, enjoy!
Now you can find a live example and download the sources.
UPDATE
A guy left a review on Stumble saying: "CDATA - Character Data. Use it. It's what it's there for".
At the very beginning I wrote that I didn't like this solution, but now I'd like to give more information on why I DON'T like CDATA:
- It increases the file size
- Your XML file becomes bloated and less readable
- If you need a new line break (which is the point of this post) you have to actually make the new line in the XML, destroying the formatting
Here is an example:
<items>
<item><![CDATA[This is the first line.
And this goes on a new line.]]></item>
</items>
20 Comments
1 Elaine wrote:
I have been trying to do this for days with CDATA. Your solution is great!!!!
Thanks!
2 gyo wrote:
glad you liked it!
3 Brendan wrote:
Hey, this seems like a really handy little technique, but for some reason it's not working for me. I've got This is line 1. 
 This is line 2
Any help would be greatly appreciated!
Brendan
4 gyo wrote:
Hi Brendan,
maybe it's a stupid thing but... did you inlcude the semicolon ";" at the end?
5 Bryce wrote:
Thanks. I am new to Flash and XML this helped a lot, for some reason I did have to set mine to HTML text, BUT I am using AS3. That may be the culprit...
6 gyo wrote:
You're welcome, Bryce!
I didn't check this in AS3, and your feedback is precious.
You could have used < ![CDATA and < br/ > since you have htmlText, but I still prefer the solution: simple, quick, effective.
7 Thomas wrote:
It cannot be said loud enough: THANK YOU! I'm a fairly knowledgeable designer/developer, but this was driving me nuts. You have to love the simple solutions....once you find them. Thanks again for publishing this.
8 Thomas wrote:
Oh, and it works just fine in AS3...
9 gyo wrote:
Hi Thomas, thanks for your feedback!
I updated the post to inform people that it works for both AS2 and AS3.
10 raj wrote:
Hi It did not work for me My XML is read by flash I have some thing like
I tried something like this but the output is comming as hi there 
 how are you doing. insted of breaking the line
Please help me with any suggestions thankyou
11 gyo wrote:
Hi Raj,
I made a practical example, you can find it in the post!
cheers
12 zzz wrote:
it works, but with small "x"
exactly as in an example.
thank Gyo
13 Nightly wrote:
Thanks very much for so great handy tool! That works awesome! The point is my XML was a huge list which consist of names.like 150 lines. it would be crazy to use CDATA. and the AS 3, is what Im using. the tools is working for me!
14 Danne wrote:
What if I use an attribute with a string from the xml like this:
Home
How do I do this then?
D
15 gyo wrote:
I think some characters got cut from your example, please give it another try so that I can understand, thanks!
16 Danne wrote:
This with attribute dosen´t work:
Danne/
17 Danne wrote:
18 Danne wrote:
I cann´t paste a comment from code on this field I don´t know whats the problem!
19 Danne wrote:
gallery
album title="Music from 
I skymningen"/
/album
/gallery
20 Danne wrote:
I could paste this without the tags could you see what I mean?
Danne/