Add GET and POST variables to Flash files through FlashVars
Using SWFObject is the simplest and best way to embed SWF files into HTML.
Download swfobject.zip file and put the swfobject.js next to the PHP file which embeds the SWF (note that the PHP script below won’t work if the file has an .html extension, and you’ll have to test it on a webserver which has PHP installed).
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
<?php
if(count($_GET) > 0 || count($_POST) > 0) {
$phpFlashVars = "";
foreach ($_GET as $var => $value) {
$phpFlashVars .= 'flashvars.'.$var.'="'.$value.'";';
}
foreach ($_POST as $var => $value) {
$phpFlashVars .= 'flashvars.'.$var.'="'.$value.'";';
}
}
print($phpFlashVars);
?>
var params = {};
var attributes = {};
swfobject.embedSWF("main.swf", "flashDiv", "600", "750", "9.0.0", false, flashvars, params, attributes);
</script>
</head>
<body>
<div id="flashDiv"></div>
</body>
</html>
So let’s say you’re naming this file main.php and you’re putting it in the root folder of your webserver.
Accessing www.yourserver.com/main.php?var=value will send the var variable with the specified value to the main.swf file.
Now you can use that value in Flash!
In ActionScript 2 you can simply access _root.var
Note that _root.var has the type String and you’ll have to convert it if it’s a number for example Number(_root.var);
In ActionScript 3 it’s root.loaderInfo.parameters["var"]



Leave a Reply