I have upgraded the QueryString API from an all static utility class to a much more robust API which now supports parsing, inspecting and modifying query strings.
The new QueryString API retrieves a query string for a Flex application via ExternalInterface. Therefore a query string which has been supplied to an application can be retrieved from an html wrapper (e.g. .html, .jsp, .aspx, etc) as well as a .swf file.
Developers can also utilize the new API to perform CRUD operations on an arbitrary query string supplied to the QueryString constructor. I have also added complete support for encoding and decoding a query string as well as appending a query string to separate URLs.
Modifications of a QueryString are now fully supported and allow parameters in a QueryString object to be created, read, updated and deleted.
The QueryString constructor takes a url as an argument. This argument is optional, and, if specified instructs the QueryString object to use the specified url for all subsequent operations. If the url is not specified the QueryString object will assume the aplication query string is to be used for all operations.
Unfortunately, ActionScript 3 does not support constructor / method overloading so the url parameter is used to achieve the correct functionality based on context.
Below is a typical use-case which demonstrates how to instantiate a new QueryString object which defaults to the application’s querystring:
|
1 2 3 4 5 6 7 |
var querystring:IQueryString = new QueryString();
//defaults to application querystring
trace( querystring.getQueryString() );
//outputs application querystring |
Optionally, you can choose to use a specific QueryString by passing it to the constructor:
|
1 2 3 4 5 6 7 8 9 |
var url:String = "http://localhost/app.html?name=Adobe Flex";
var querystring:IQueryString = new QueryString( url );
//defaults to querystring specified in constructor
trace( querystring.getQueryString() );
//name=Adobe Flex |
Additional usage examples for all method can be found in the accompanying ASDoc.
You can view the source for the IQueryString interface and concrete QueryString implementation as well as the asdocs.
QueryString API is protected under the MIT license.
{ 3 comments to read ... please submit one more! }