This was a nice little exercise getting some name value pair data into an embedding flash object. swfobject 2.0 has a great new way to pass objects with your variables to your swf.
This is the javascript:
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {dataFeedXML: "./data/regions_feed.xml"};
swfobject.embedSWF("swf/filename.swf", "flashDiv", "687", "486", "9.0.0", "swf/expressInstall.swf", flashvars);
</script>
I had to use the dot in the beginning of my dataFeedXML path string on my local apache installation. This may not be case depending on your server environment.
Here is the html code:
<div id="flashDiv">
<h1>Oops looks like you don't have flash!</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
Here is where things get interesting if you are used to previous versions of flash. In as2 we could reference undeclared variables.
Example if we were to write this on the first frame of our main timeline: var myExternalVar:String = dataFeedXML; we would recieve the error: 1120: Access of undefined property dataFeedXML.
dataFeedXML is of the scope this, and this is [object MainTimeline]. The property [dataFeedXML] doesn’t exist at compile time. We have to access root.loaderInfo.parameters; to access the flashvars passed to our swf. The particular variable in question could be references as such: root.loaderInfo.parameters.dataFeedXML
If you would like to get all of the flash vars use:
for (var fv in root.loaderInfo.parameters) {
trace("flashvar name = "+fv);
trace("flashvar value = "+root.loaderInfo.parameters[fv]);
}
No Comment Received
Leave A Reply