URL Encode a string in ActionScript

snipped by vixiom

Here are a couple of methods that are similar to PHP's urlencode.

To escape characters use escape()

var str1:String = "I like R & B music";
var str1Encoded:String = escape(str1);
trace(str1Encoded);
// = I%20like%20R%20%26%20B%20music

If you need to encode the string into a valid URI (Uniform Resource Identifier)

var str2:String = "but Drum & Bass is better";
var str2Encoded:String = encodeURI(str2);
trace(str2Encoded);
// = but%20Drum%20&%20Bass%20is%20better