Skip to main content
markGodriguez
Known Participant
September 25, 2009
Answered

retrieve parameter value from URL query string

  • September 25, 2009
  • 3 replies
  • 2045 views

this seems like it should be simple but for some reason i can't figure out how to get the value of a variable out of a URL query string.

if this is in my location bar: http://www.whyu.com/whyplayer.html?chosenCLIP=movie

and i just want the value of "chosenCLIP" to use in my loaded SWF file, how do i do it in AS3?

This topic has been closed for replies.
Correct answer

I think the easiest way is to use SWFObject.


In your HTML:

var flashvars = {};
if (swfobject.getQueryParamValue("chosenCLIP")) {
  flashvars.clip = swfobject.getQueryParamValue("chosenCLIP"); 
}
swfobject.embedSWF("myMovie.swf", "myContent", "550", "400", "9.0.0", "", flashvars);

And the clip variable will be available as a FlashVar to your movie:


var theClip = loaderInfo.parameters.clip;

3 replies

October 15, 2009

Wow! You guys are making this really complicated. All you need to do is this:

loaderInfo.parameters.myVariable

In AS2 I believe they are loaded into the root automatically, so you can just access the variables directly.

October 16, 2009

and what if i want to do it with only one hand and blindfolded in AS5??

THANKS!

ciao

Correct answer
September 25, 2009

I think the easiest way is to use SWFObject.


In your HTML:

var flashvars = {};
if (swfobject.getQueryParamValue("chosenCLIP")) {
  flashvars.clip = swfobject.getQueryParamValue("chosenCLIP"); 
}
swfobject.embedSWF("myMovie.swf", "myContent", "550", "400", "9.0.0", "", flashvars);

And the clip variable will be available as a FlashVar to your movie:


var theClip = loaderInfo.parameters.clip;

markGodriguez
Known Participant
September 25, 2009

that did it!

thank you, thank you, thank you.

September 25, 2009

You're welcome

September 25, 2009
markGodriguez
Known Participant
September 25, 2009

i still can't make it work even with that. i'm not sure what i am doing wrong or even if i am testing it properly. i really need a good simple version that has what is happening on the HTML and flash side of the scripts. even better would be actual files that i can use so there is nothing assumed.

thanks for trying.