GET Variables with Flash MX 2004 2

Posted by Jimmy'z on June 24, 2006

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:

mp3Player.swf?fileName=1.mp3&volume=50

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();
parameters.decode(queryString);

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.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. [...] Okay, I just posted on how to Pass Variables into Flash by using a GET string approach, but there is better way. Using FlashVars to pass in variables is super easy. [...]

  2. rex_raikov Sat, 02 May 2009 15:38:26 UTC

    ok..thankx 4 the tips…iam just a flas beginner..and im having trouble using variables on my flash

    thx 4 the tips

Comments