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.
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…
Book-mark this post
Book-mark this post in Del.icio.us, Furl, Digg, Stumble Upon, whatever...
Mouse-over the image and choose your bookmark:






alQpr » Blog Archive » swf in WordPress said,
September 25, 2006 at 2:32 am
[...] This post by Zac at squareCircleZ discusses SWFObject, an XHTML compliant javascript for inserting .swf files in blogs [...]