Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For encoding URL parameters, both %20 and + are valid representations of the space character, and both <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#toString()" rel="nofollow noreferrer">URLVariables.toString()</a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/URLUtil.html#objectToString()" rel="nofollow noreferrer">URLUtil.objectToString()</a> emit compliant application/x-www-form-urlencoded data using the former (per <a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf" rel="nofollow noreferrer">ECMA-262</a>). The <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#encodeURI()" rel="nofollow noreferrer">encodeURI()</a>, <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#encodeURIComponent()" rel="nofollow noreferrer">encodeURIComponent()</a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#escape()" rel="nofollow noreferrer">escape()</a> functions all operate similarly. From the AS3 docs:</p> <blockquote> <p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html#toString()" rel="nofollow noreferrer"><strong>flash.net.URLVariables.toString()</strong></a></p> <p>Returns a string containing all enumerable variables, in the MIME content encoding application/x-www-form-urlencoded.</p> <p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/utils/URLUtil.html#objectToString()" rel="nofollow noreferrer"><strong>mx.utils.URLUtil.objectToString()</strong></a></p> <p>You typically use this method to convert an ActionScript object to a String that you then append to the end of a URL. By default, invalid URL characters are URL-encoded (converted to the %XX format).</p> <p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#encodeURIComponent()" rel="nofollow noreferrer"><strong>encodeURIComponent()</strong></a></p> <p>Encodes a string into a valid URI component. Converts a substring of a URI into a string in which all characters are encoded as UTF-8 escape sequences unless a character belongs to a very small group of basic characters.</p> <p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package.html#escape()" rel="nofollow noreferrer"><strong>escape()</strong></a></p> <p>Converts the parameter to a string and encodes it in a URL-encoded format, where most nonalphanumeric characters are replaced with % hexadecimal sequences. </p> </blockquote> <p>Here's an example showing the usage and output of all four approaches:</p> <pre><code>import mx.utils.URLUtil; private function test():void { var url:String = "http://www.google.com/search?"; var s:String = "here is my search query"; var variables:URLVariables = new URLVariables(); variables.q = s; var o:Object = new Object(); o.q = s; trace(url + "q=" + encodeURIComponent(s)); trace(url + variables.toString()); trace(url + "q=" + escape(s)); trace(url + URLUtil.objectToString(o)); } </code></pre> <p>All four emit the same result (just as JavaScript's own encodeURIComponent() does):</p> <pre><code>// http://www.google.com/search?q=here%20is%20my%20search%20query </code></pre> <p>I agree the plus signs are easier on the eyes, though! To swap them out manually:</p> <pre><code>trace(url + "q=" + escape(s).split("%20").join("+")); </code></pre> <p>But if there's an ActionScript class or top-level function that uses plus signs instead of hex sequences for spaces, I'm not aware of it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload