AS3 Textfield New Line not being Recognized

January 14, 2014

I loaded an xml file into a program which was then used to set string based variables. The text from the xml file was contained between CDATA tags and contained the \n character as shown below:

<![CDATA[Directions:\n1. Choose a patient by clicking on a silhouette.\n\n]]>

The AS3 textfield was not recognizing the new line character when set from the xml file and was just displaying the \n within the Textfield so it appeared in the textfield like this:

Directions:\n1. Choose a patient by clicking on a silhouette.\n\n

Finally found a solution from a post from 2008:

Newline characters not recognized when parsing external xml file

Once I added the code recommended on the site:

myText.replace(/\\n/g, "\n");

The new line was recognized in the textfield.

Reminder /g is a flag to globally replace all the occurrences.

Advertisements