开发者

Is there new line constant in actionscript or flex

I want to add a newline to a string 开发者_如何学Gotext 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.


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.


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


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.


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

\r\n


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜