While working on my latest project at Provo Labs, I needed to use something like GET Variables with Flash MX 2004, so that I could pass parameters into the Flash application from the html page that it sat on. Here’s how to do it:
First, in the object tag on your html page, put your parameters on a url-encoded query string like so:
Make sure you place the full url with the querystring in both the embed tag and the param movie=”” tag as Internet Explorer uses the param tag and Firefox uses the embed tag to determine the source of your SWF.
Now for the ActionScript that does the magic:
var selfURL:String = new String(_root._url);
var queryString:String = new String();
var splitAt:Number = selfURL.lastIndexOf(“?”)+1;
var qsLength:Number = selfURL.length – splitAt;
queryString = selfURL.substr(splitAt,qsLength);
// parse the querystring into usable variables
var parameters:LoadVars = new LoadVars();
Your parameters variable will now act as the $_GET variable in php, so you can get your parameters by referencing parameters[‘id’] and so forth.