Posted by BGoulette in SWF Studio V3 on Aug 04 2008, 05:19 pm

If I explicitly set the text of a showMsgBox prompt to something like:

prompt:"This is line one\nThis is line two"

it works. If I use text retrieved from an XML file that looks like this:

<promptText><![CDATA[This is line1\nThis is line 2]]></promptText>

or even this:

<promptText>This is line1\nThis is line 2</promptText>

the newline characters aren't translated appropriately. I've tried the following:

prompt:promptText.toString()

and

prompt:String(promptText);

and even

var tmpString:String=String(promptText); // also, promptText.toString();
prompt:tmpString


but with the same results.

Any idea what I'm doing wrong? Thanks!


Posted by northcode in SWF Studio V3 on Aug 04 2008, 05:33 pm

You need to read String Literals vs. String Values. Basically the \ is only treated as a special character when it appears in quotes in code. When you're reading from a file, getting use input, etc. then a \ is just another character.


Posted by BGoulette in SWF Studio V3 on Aug 04 2008, 05:37 pm

Ok. I'd also tried "\\n," too, but with no results. I'm guessing for the same reasons?

Is there anyway to get \n recognized as newlines when they're part of a predefined string? I apologize for my dense-ness!

Edit: All right, so maybe it's not the best way, but the following worked:

prompt:myXMLsource.replace(/(\\n)/g, "\n")

FYI :) (I'm sure such an approach could potentially lead to other problems, but it works for me for now! ;) )


Posted by northcode in SWF Studio V3 on Aug 04 2008, 05:44 pm

If s is loaded from a file then you can just replace \\n with \n like this to get what you want...


s = s.split("\\n").join("\n");