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.
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.
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
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.
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));
And if you are putting them in MXML, you have to encode it per XML:
Cheers