escape( ) Global Function | Flash 6 |
encode a string for safe network transferFlash 5; enhanced to support UTF-8 in |
A string (or an expression that yields a string) to be encoded.
An encoded version of string.
The escape( ) function creates a new encoded string, based on a supplied string. The new string contains a hexadecimal escape sequence in place of any character in the supplied string that is not a digit or a basic, unaccented Latin letter between A and Z or a and z. As of Flash Player 6, the replacement hexadecimal escape sequences take the following format:
If System.useCodepage is false (the default), the character is replaced by one or more hexadecimal escape sequences of the form %xx, representing the UTF-8 sequence for the character. Characters in the Unicode range 0-127 are encoded as %xx (single-byte), characters 128-2047 are encoded as %xx%xx (double-byte), and characters 2048 and above are encoded as %xx%xx%xx (triple-byte).
If System.useCodepage is true and the system is not an Asian language double-byte system, the character is replaced with a hexadecimal escape sequence %xx, where xx is the hex code point for the character. The code point is determined using the system code page (typically Latin 1 on most Western computers). Note that on Macs, the system code page is Mac Roman, but Flash uses Latin 1 instead.
If System.useCodepage is true and the system is an Asian language double-byte system, the character is replaced with a hexadecimal escape sequence %xx or %xx%xx, using the double-byte character encoding supported by the system (for example, Shift-JIS).
Flash Player 5 behaves as if System.useCodepage is always true (earlier versions did not support escape( )).
The escape( ) function is sometimes used when a Flash movie sends information to server applications or writes cookies in a browser. To decode an encoded string, use the global unescape( ) function.
Note that for characters above Unicode code point U+007F (decimal 127), the UTF-8 escape sequence is not the same number as the Unicode code point! For example, the code point for é is U+00E9 (decimal 233), but the UTF-8 sequence is %C3%A9. See the LoadVars class for information on loading external encoded text.
trace(escape("6-5 is 4")); // Displays: 6%2D5%20is%204 (- is %2D, space is %20) trace(escape("resumé")); // Displays: resum%C3%A9