escape function

escape(expression:String) : String

Converts the parameter to a string and encodes it in a URL-encoded format, where all nonalphanumeric characters are replaced with % hexadecimal sequences. When used in a URL-encoded string, the percentage symbol (%) is used to introduce escape characters, and is not equivalent to the modulo operator (%).

Availability: ActionScript 1.0; Flash Player 5

Parameters

expression:String - The expression to convert into a string and encode in a URL-encoded format.

Returns

String - URL-encoded string.

Example

The following code produces the result someuser%40somedomain%2Ecom:

var email:String = "someuser@somedomain.com";
trace(escape(email));

In this example, the at symbol (@) was replaced with %40 and the dot symbol (.) was replaced with %2E. This is useful if you're trying to pass information to a remote server and the data has special characters in it (for example, & or ?), as shown in the following code:

var redirectUrl:String = "http://www.somedomain.com?loggedin=true&username=Gus";
getURL("http://www.myothersite.com?returnurl="+ escape(redirectUrl));

See also

unescape function


Version 8

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001725.html