views:

73

answers:

6

I want to add a newline to a string text and I was wondering if there is a newline constant in actionscript 3? For example in .net there is an Environment.NewLine that is a string, containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.

+2  A: 

AS2 used to have a newline keyword but it is deprecated. There is currently no such constant. I generally just use \n with no problems.

James Fassett
+1  A: 

You need not do that if you're trying to display string in your SWF, because your string is displayed on Flash player that uses \n for newlines.

If you're trying to create a file based on the OS (to be saved onto the local machine maybe), you can check the OS using the static variable flash.system.Capabilities.manufacturer

Amarghosh
+3  A: 

The cheat sheet for migration from AS2 to AS3 states:

newline
Removed
Use the escape sequence composed of the backslash character followed by the character "n" (\n).

In other words, there is no such constant in AS3. Flash, in general, has the advantage of "being it's own platform", so you can get away with some platform dependencies.

nikc
+1  A: 

if \n does not work well in all cases try with

\r\n
Adrian Pirvulescu
+1  A: 

I would personally use (see code snippet) and would return 10. I prefer this than testing against "\n", but it's up to you.

var text : String = "\n";
trace(text.charCodeAt(0));
stickupkid
+1  A: 

And if you are putting them in MXML, you have to encode it per XML:

Cheers

Richard Haven