Flex 2: How to get URL query-string variables within Flex application

This has been a reoccurring problem on flexcoders and in the small circle of Flex developers I know. It is a problem that I had encountered and thought that I had found an answer; Abdul Qabiz's Blog posting (duplicated) had described a (in his own words) "quick-and-dirty" solution. That method works well for pulling the String value of the parameters passed in the query-string, but what do you do when those values are URL Encoded? Below is my (and I use my very loosely as it isn't much to claim) solution that provides similar behavior as described in Abdul's posting, but requires significantly less code and is much more readable:

Source and Usage

Given the URL:
http://deepthoughts.orsomethinglikethat.com?myParam=My%20Value

the return value is "My Value".

This may not be the ideal solution if the URL is pointed directly to the SWF or if you choose to make your parameters available via FlashVars.

Spread the word... These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DZone
  • Slashdot
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Technorati

3 Comments so far

  1. Mike from Boston on April 10th, 2007

    This article is exactly what I am looking for.
    Unfortunately, the code is missing from the page.
    Is there any way to fix this in the post ?
    Any info would be helpful.

    Thanks,
    Mike Gray
    michael.gray.m2k@fmr.com

  2. Luke Pillow on April 10th, 2007

    Mike,

    I’ve updated the post with the linked source.

    I had been having problems with the WordPress plugin I’d been using. I’ve since given up on embedding the source.

    I hope this helps. Let me know if you have any other questions.

  3. David de Bruine on April 7th, 2008

    Hi Luke,

    The line in the source code:
    urlVars.decode(”window.location.search.substring”);

    for me throws an error.

    I replaced it with:

    urlVars.decode(ExternalInterface.call(”window.location.search.substring”, 1));

    And all is good.

Leave a reply