4 Replies Latest reply on Oct 18, 2010 8:45 AM by Scaljeri

    retrieve url parameters

    Scaljeri Level 1

      Hi All

       

      I need to retrieve all the parameters of the url, for example if the URL looks like

       

      http://www.mydomain.com/MyApp.html#firstName=Nick;lastName=Danger
      
      (example used: http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_5.html )

       

      Anyway, the code to extract the parameters looks like

      
      then the parameters are extracted like
      
              private function init(e:Event):void {
                  bm = BrowserManager.getInstance();                
                  bm.init("", "Welcome!");
      
                  /* The following code will parse a URL that passes firstName and lastName as
                     query string parameters after the "#" sign; for example:
                     http://www.mydomain.com/MyApp.html#firstName=Nick&lastName=Danger */
                  var o:Object = URLUtil.stringToObject(bm.fragment, "&");                
                  fName = o.firstName;
                  lName = o.lastName;                
              }
      
      
      However, the fName and lName remain empty. Any suggestion how to retrieve URL parameters ?
      cheers
      Luca

        • 1. Re: retrieve url parameters
          Flex harUI Adobe Employee

          Looks like you're using ; instead of &

          • 2. Re: retrieve url parameters
            Scaljeri Level 1

            I tried everything!

            But did you try to run the example and did it work for you ?

            Which flex version do you use ? I've tried 3.5 and 4.1

             

            cheers

            • 3. Re: retrieve url parameters
              yellow267

              Hi scaljeri...try this...it worked for me last week:

               

               

              protected function readQueryString():String{
                        var urlParams:Dictionary = new Dictionary();
                        
                        if (ExternalInterface.available)
                        {
                             var fullUrl:String = ExternalInterface.call('eval', 'document.location.href');
                             var paramStr:String = fullUrl.split('?')[1];
                             if (paramStr != null)
                             {
                                  var params:Array = paramStr.split('&');
                                  var s:String;
                                  for (var i:int=0; i < params.length; i++)
                                  {
                                       var kv:Array = params[i].split('=');
                                       urlParams[kv[0]] = kv[1];
                                       s =  kv[1];
                                  }
                             }
                             return s;
                        }
                        return null;
              }

               

              yellow

              1 person found this helpful
              • 4. Re: retrieve url parameters
                Scaljeri Level 1

                thnx, I'll use that!!

                 

                Still very odd why my example doesn't work, but maybe it only works with Flex 2

                 

                cheers