Posted By

publicbroadcast on 04/22/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

alexaivars
thastyle
thastylos


qet query string


 / Published in: ActionScript 3
 

example: public var qs:QueryString

qs = new QueryString(); qs.parameters.XXXX

trace(qs.url)

  1. package com.abdulqabiz.utils
  2. {
  3. import flash.external.*;
  4. import flash.utils.*;
  5.  
  6. public class QueryString
  7. {
  8.  
  9. private var _queryString:String;
  10. private var _all:String;
  11. private var _params:Object;
  12.  
  13. public function get queryString():String
  14. {
  15. return _queryString;
  16. }
  17. public function get url():String
  18. {
  19. return _all;
  20. }
  21. public function get parameters():Object
  22. {
  23. return _params;
  24. }
  25.  
  26.  
  27. public function QueryString()
  28. {
  29.  
  30. readQueryString();
  31. }
  32.  
  33. private function readQueryString():void
  34. {
  35. _params = {};
  36. try
  37. {
  38. _all = ExternalInterface.call("window.location.href.toString");
  39. _queryString = ExternalInterface.call("window.location.search.substring", 1);
  40. if(_queryString)
  41. {
  42.  
  43. var params:Array = _queryString.split('&');
  44. var length:uint = params.length;
  45.  
  46. for (var i:uint=0,index:int=-1; i<length; i++)
  47. {
  48. var kvPair:String = params[i];
  49. if((index = kvPair.indexOf("=")) > 0)
  50. {
  51. var key:String = kvPair.substring(0,index);
  52. var value:String = kvPair.substring(index+1);
  53. _params[key] = value;
  54. }
  55. }
  56. }
  57. }catch(e:Error) { trace("Some error occured. ExternalInterface doesn't work in Standalone player."); }
  58. }
  59.  
  60. }
  61. }

Report this snippet  

You need to login to post a comment.