Thursday, June 2, 2011

AS3 Code Snippet - Getting parameters from URL query string

Hello,

Heres a quick code snippet that you can use to get parameters in the url which a swf is hosted on.
E.G: http://mysite.com/myGreatSWF.swf?paramName=paramValue

Code Snippet:

trace(this.loaderInfo.parameters.paramName);
// outputs "paramValue", if the url is "http://mysite.com/myGreatSWF.swf?paramName=paramValue"


loaderInfo.parameters contains a Object with all the parameters in the url requesting the swf, you could use "swfname.swf?test=thetestvalue" for instance, and get it in the swf file using "loaderInfo.parameters.test"

You should also check if the query (test in this case) exists, in order to avoid errors.

2 comments:

  1. Cool! I like your tutorials, can you show me how to check if it exists?? Thanks

    ReplyDelete
  2. You can use an IF statement, like if(myVar != null)

    ReplyDelete