ProblemYou want to add whitespace characters, such as tabs or newline characters, to your string. SolutionUse the escape sequences for the special characters. DiscussionThere are five special whitespace characters with escape sequences, as shown in Table 12-1.
You can use these escape sequences within a string; they are most useful when displaying a string value in a text field: // Results in a string value: these words are separated by tabs var example:String = "these\twords\tare\tseparated\tby\ttabs"; /* Results in a string value: these words are separated by newlines */ var example:String = "these\nwords\nare\nseparated\nby\nnewlines"; Unlike previous versions of ActionScript, ActionScript 3.0 no longer includes support for the newline constant. If you have code that uses newline anywhere, you will need to replace it with the \\n escape sequence. The result is the same. // Generates a compile error replace newline with "\n" to compile var error:String = "two" + newline + "lines"; // Compile error: "Access of // undefined property 'newline'" Within Flash, the newline, form feed, and carriage return characters all result in the same display. However, when you load content into Flash from external sources, some values will have newline characters, some will have form feeds, and some will have carriage returns. |