08.09Passing parameters to a Flash 9 ActionScript 3 SWF file
Hi everyone, I found this blog entry which shed light on how to pass variables to your SWF this way :
CODE:
-
light.swf?artist=yolanda&page=12
Here is some usefull function you can use. Put it in your Document Class. For those who don't know what that is, just put it on the stage on Frame 1 then.
Actionscript:
-
protected function getSwfParam(name:String, defaultValue:String):String
-
{
-
var paramObj:Object = LoaderInfo(stage.loaderInfo).parameters;
-
-
if(paramObj[name] != null && paramObj[name] != "")
-
return paramObj[name];
-
-
else
-
return defaultValue;
-
}
So it's quite simple to use it:
Actionscript:
-
var artist:String = getSwfParam("artist", "defaultArtist");
VoilĂ !
Inspiration
I used these articles as inspiration. Make sure you READ the FIRST COMMENT of the post since it outlines an important omission from the author.
Cheers!

Thank you! You just saved my life.
August 25th, 2009 at 10:25 am
I’m trying to pass a variable like this from as3
private var _movie:String=”mymovie.swf”
var mRequest:URLRequest = new URLRequest(”swfloader.swf?m=”+_movie);
But I get a url not found error, not because it doesn’t find mymovie.swf, but it can’t load swfloader.swf at all, I don’t understand why.
If I remove the “?m=+_movie” then it works, but of course it doesn’t load the final movie…
August 31st, 2009 at 6:24 pm
Really Cool
Thanks for solution!!!!!!!!11
September 5th, 2009 at 3:20 am
Another interesting thing I found out is that you can add the code ‘+document.location.search+’ to the JavaScript that calls the swf file, so that you don’t need to hardcode the variable in the html. The result is something like this:
’src’, ’swf_file_name’+document.location.search+”,
‘movie’, ’swf_file_name’+document.location.search+”,
October 1st, 2009 at 11:55 am
really preciated!!!!! mate!
December 8th, 2009 at 7:19 am
Thanks, finally i found it
you saved some hours for me
January 20th, 2010 at 7:08 am
you made my day (or nigth).
=)
April 19th, 2010 at 9:55 pm
thx a lot..
July 25th, 2010 at 5:08 am