views:

509

answers:

3

Hi,

I have created a XML image gallery, which displays text in between each slide. Now I have created a movie clip with a dynamic text field (with Render HTML selected) to display the text from the XML which is pushed into an array. Now, this all works great BUT... /n or /r is not creating a new line break (as they need to be custom). Yet if I create an Array and manually push strings "Bla bla bla /n bla bla bla" I get a line break. I have tried converting the Array item to string (even though it already is), I would also avoid creating textField = new textField() any Ideas would be welcomed.

Cheers

+1  A: 

Edit

You have two choices :

-as suggested put replace in your XML the \n by a <br/> but encoded to be a valid XML &lt;br/&gt;

<image imageFile="GrandOpening1.jpg"
       text="XXXXX&lt;br/&lt;XXXXXX&lt;br/&lt;XXXX XXXX XXXXXX">
</image> 

-or at runtime when filling your textfield replace the \n by a <br/>

[email protected]().split("\\n").join("<br/>");

/n /r is not correct it 's \n \r.

Have you enable multiline option for your TextField.

Patrick
Yeah, sorry...I meant /n and yes Multiline is enabled
Jono
+1  A: 

Since your TextField is HTML enabled, it would be better to use a <br> tag to create a new line break.

Zed-K
If I use <br> in xml it gives me TypeError: Error #1095: XML parser failure: Unterminated attribute.
Jono
Just put your text in a <![CDATA[ ... ]]> block inside your XML, so the tags used inside are not processed by the XML parser. ( http://www.w3schools.com/xmL/xml_cdata.asp )
Zed-K
Nailed it, taking the text out of the attribute and nesting it in the node with CData works. Tres Bon @Zed-K
Jono
A: 

\n \r only works in runtime and
won't work. I use a custom string to represent linebreak "#BR#" for example. Before you pass the string to the text box, replace all instances of "#BR#" with "\n" using regular expression.

var str:String = xmlString; var pattern:RegExp = /#BR#/ig;//target all instances of #BR#(case insensitive) txt_textbox.text=str.replace(pattern, "\n");

Desmond Liang