SWFObject – compliant and works nicely in Wordpress
I was impressed – and rather bemused – when a friend today pointed out that I had examples of non-XHTML-compliant code on my blog. (I am picky about making sure my code is standards-compliant.)
Anyway, I had been meaning to implement SWFObject, a javascript solution for displaying Flash, for a few weeks. So I was motivated to do it just now and below is the result. (It will just look like another YouTube video, but the code behind it is very neat.)
Essentially it involves calling the JS file “swfobject.js” and then passing the movie parameters to a function. The javascript then replaces the content of a <div> with the movie. Clever stuff – and XHTML compliant
. Of course, replace where I have *** with your own path to the js script.
Updated: This is fussier that I first thought. Wordpress adds various <br /> code bits in the middle of the javascript, and this can mess with how it works. To solve the problem, remove all hard carriage returns (line spaces) within the code (except the “var so” line), so it is all bunched up together. I have updated the following:
<script type="text/javascript" src="***/swfobject.js"></script><div id="flashcontent">This text gets replaced by the Flash movie.</div><script type="text/javascript"><!--
var so = new SWFObject("http://www.youtube.com/v/hY1H0rvoLUY", "mymovie", "425", "350", "7", "#efefef"); so.write("flashcontent"); //--></script>
Now, you can watch the movie “Reppin the Calculus”.
Go on, I know you want to…
Related posts:
- What’s the problem with your math? A cute math video enveloped in a cute skin from...
- PS3 Home – a worthy challenger for SecondLife? Serious challenge for second life, or not......
- Friday math movie – math problem solving with mind maps This week's movie gives you some good tips on how...
- Friday math movie – Dancing Honeybee Using Vector Calculus to Communicate Bees use vectors to show fellow workers where the food...
- Blog Action Day – the Environment Blog Action Day aims to "put a single important issue...

25 Sep 2006 at 2:32 am Link to this comment
[...] This post by Zac at squareCircleZ discusses SWFObject, an XHTML compliant javascript for inserting .swf files in blogs [...]
16 Sep 2009 at 5:08 am Link to this comment
AWESOME. I was hoping to pull this off without having to install some ridiculous plug-in. Thanks so much for the post – saved me a ton of heartache and swearing. :]
16 Sep 2009 at 8:56 am Link to this comment
You’re welcome, Matt. Anything to reduce heartache!
1 Dec 2009 at 5:41 am Link to this comment
having an issue with this in my wp blog:
This text gets replaced by the Flash movie.<!–//
^– That’s my code, not sure whats wrong. any ideas? the movie is simply not showing up.
5 Dec 2009 at 11:46 am Link to this comment
Hi Robert
How about publish your post and let me know the URL so I can try to spot the problem for you.