Avg. Rating 3.5

Problem

When entering a value for the text attribute of a Text component in MXML, if the text contains a line break ("\n"), the line break will not be rendered, and the text "\n" will be displayed instead.

Solution

Use "{'\n'}" to enter the line break in the text.

Detailed explanation

When entering a value for the text attribute of a Text component in MXML, if the text contains a line break ("\n"), the line break will not be rendered, and the text "\n" will be displayed instead.

For example, the following code will display two Text components - both include the "\n" line break character, but only the second one will render the break.

<mx:Text text="Line \n Break" />

<mx:Text text="Line {'\n'} Break" />


This will display as follows:



Wrapping the line break character with the curly braces (similar to data-binding) will allow the break to be rendered.

Note: This is not needed when setting the value of a Text component's text via ActionScript, only when using the text attribute of the MXML tag.
Report abuse

Related recipes