I'm trying to load a URL/GET variable into a FlashVar to be used in AS3. It just traces back in AS3 as undefined.
Here is my JS ($_GET['building'] is set to something and echos out correctly):
<script type="text/javascript" src="<?php echo site_url(); ?>js/swfobject.js"></script>
<script type="text/javascript">
<?php if(isset($_GET['building'])){ ?>
var flashvars = { building: '_<?php echo $_GET['building']; ?>' };
<?php } else { ?>
var flashvars = { };
<?php } ?>
var params = {};
var attributes = {};
swfobject.embedSWF("PlanEventTool_cs5-1.swf", "flashContent", "900", "700", '9.0.0', '<?php echo site_url(); ?>js/expressInstall.swf', flashvars, params, attributes);
</script>
And my AS3:
var allFlashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
buildingString = String(allFlashVars['building']);
trace(buildingString);
Been looking at this for a while and I'm sure I'm missing something small.
Any ideas?
Rendered JS:
var flashvars = { };
flashvars.building = "_grandstand";
var params = {};
var attributes = {};
var flashObj = "PlanEventTool_cs5-1.swf?t=" + new Date().getTime(); // anti-cahce
swfobject.embedSWF(flashObj, "flashContent", "900", "700", '9.0.0', 'expressInstall.swf', flashvars, params, attributes);
Rendered HTML:
<object width="900" height="700" type="application/x-shockwave-flash" data="PlanEventTool_cs5-1.swf?t=1334695440505" id="flashContent" style="visibility: visible;"><param name="flashvars" value="building=_grandstand"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="AllowNetworking" value="all"></object>
If you are sure $_GET['building'] exists then the problem is probably with the SWF being cached.
Also I would neaten up your code a tad
<script type="text/javascript" src="<?php echo site_url(); ?>js/swfobject.js"></script>
<script type="text/javascript">
var flashvars = { };
<?php
if(isset($_GET['building'])){
echo 'flashvars.building = ' . $_GET['building'] . ';';
}
?>
var params = {};
var attributes = {};
var flashObj = "PlanEventTool_cs5-1.swf?t=" + new Date().getTime(); // anti-cache
swfobject.embedSWF(flashObj , "flashContent", "900", "700", '9.0.0', '<?php echo site_url(); ?>js/expressInstall.swf', flashvars, params, attributes);
</script>