Month: October 2009

SWFAddress with SWFObject gotcha’s

So a couple of things I’ve run into while using both SWFAddress and SWFObject. Thanks to some helpful blog posts, I found the answer to my issue was the order of my include statements.

Issue: Back/Forward isn’t dispatching SWFAddressEvent.CHANGE events. Some may be used to referring to that as the SWFAddress.onchange event. Either way, SWFAddress was working great, except for Back/Forward functionality.

Here’s what my simple embed code looked like before.

<script type=”text/javascript” src=”assets/script/SWFAddress.js”></script>

<script type=”text/javascript” src=”assets/script/swfobject.js”></script>

<script type=”text/javascript”>
window.onload = function() {
var so = new SWFObject(
“main.swf”, // source
“Main”, // id
“980”, // width
“100%”, // height
“10”, // required version
“#FFFFFF” // background color
);
so.addParam(“allowScriptAccess”, “always”);
so.addParam(“wmode”, “opaque”);
so.addParam(“FlashVars”, “language=en_US”);
so.write(“appContainer”);
}

</script>

And here’s the version with Back/Forward working!

<script type=”text/javascript” src=”assets/script/swfobject.js”></script>

<script type=”text/javascript” src=”assets/script/SWFAddress.js”></script>

<script type=”text/javascript”>
window.onload = function() {
var so = new SWFObject(
“main.swf”, // source
“Main”, // id
“980”, // width
“100%”, // height
“10”, // required version
“#FFFFFF” // background color
);
so.addParam(“allowScriptAccess”, “always”);
so.addParam(“wmode”, “opaque”);
so.addParam(“FlashVars”, “language=en_US”);
so.write(“appContainer”);
}

</script>

See a difference? The swfobject include statement is BEFORE the swfaddress include. Yes, it was really that easy. Thanks to NOBIEN for figuring out this simple fix. If you are looking in the error console trying to find a javascript error, it doesn’t happen. That non-error is the tricky part in this gotcha. It’s very difficult to debug a problem when you have no idea what the problem is.

This same problem will also arise if there is not an ID set for your content in SWFObject.