Posted By

scottwatkins on 04/07/11


Tagged

actionscript querystring as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

burnandbass


Get Querystring as an Object


 / Published in: ActionScript 3
 

This function will take the querystring from the URL and return it as a property:value paired object.

  1. /**
  2.  * _getQuerystringAsObject
  3.  * returns the URL querystring as an object
  4.  */
  5. private function _getQuerystringAsObject():Object
  6. {
  7. var _params:Object = {};
  8. var _queryString:String;
  9. var _all:String;
  10.  
  11. try
  12. {
  13. _all = ExternalInterface.call("window.location.href.toString");
  14. _queryString = ExternalInterface.call("window.location.search.substring", 1);
  15. if(_queryString)
  16. {
  17. var params:Array = _queryString.split('&');
  18. var length:uint = params.length;
  19. for (var i:uint=0,index:int=-1; i<length; i++)
  20. {
  21. var kvPair:String = params[i];
  22. if((index = kvPair.indexOf("=")) > 0)
  23. {
  24. var key:String = kvPair.substring(0,index);
  25. var value:String = kvPair.substring(index+1);
  26. _params[key] = value;
  27. }
  28. }
  29. }
  30. }catch(e:Error) { trace("ERROR"); }
  31. return _params;
  32. }

Report this snippet  

You need to login to post a comment.