We’re working on a site right now whose individual pages are comprised of a stack of separately embedded swfs. Long story short, most of the content loaded into these swfs is dependent on particular flashVar data. Since I have one collection of variables intended to be global (passed into every embedded swf), I’d created a global generic object to store those name-value pairs and then assigned individualized objects per swf to the global object (var localObject = globalObject; ) before assigning that swf its unique properties. What I didn’t realize was that the JavaScript, of course, wasn’t copying the globalObject but simply referencing it, so by the time the entire page was computed there was still only one object, it just contained all properties that were suppose to instead be set per swf embed.
What this led me to illustrate through firebug introspection and flash tracing once the swfs were loaded was that even if a generic object was set with properties to be passed into a swfobject embed as flashVars, and then passed into that swfobject embed, any changes to that generic object after the embed will be reflected by the swf once loaded. So if I type in Javascript:
var flashVarsObject = {};
flashVarsObject.foo = "bar";
swfobject.embedSWF("example.swf", "example", "400", "300", "9.0.0", "expressInstall.swf", flashVarsObject);
… the flash trace for stage.loaderInfo.foo would be “bar”.
But if, after the swfobject.embedSWF call, I further set the foo variable, such as:
var flashVarsObject = {};
flashVarsObject.foo = "bar";
swfobject.embedSWF("example.swf", "example", "400", "300", "9.0.0", "expressInstall.swf", flashVarsObject);
flashVarsObject.foo = "fighters";
… the flash trace would be “fighters”.
FlashVar name/value pairs are apparently not passed in upon calling embedSWF, but rather, the flashVar object appears to simply be referenced. This of course makes just as much sense, but what seemed to make it out of place was that using firebug, I could see the actual <object> and <param> tags rendered by swfobject. At the core, thats really all swfobject does. What is strange about it is that a <param> tag includes attributes for “name” and “value”, appearing as literal strings when rendered. Somehow, this param tag synchronously represents the flashVars object passed into embedSWF, even though the param appears to be simple strings. Keep an eye out for this little catch, and of course its best to keep JavaScript objects well separated for this sort of use.