Adding Motion and Sound: Using SWFObject to Insert Flash Videos and Presentations

Apart from the traditional web stack, Adobe’s Shockwave Flash platform is currently the most popular tool used to integrate audio and video with traditional web content.

Those who want to simplify the process of publishing compiled Flash presentations on their sites should consider using a piece of openly available JavaScript called SWFObject, created by Geoff Stearns. SWFObject uses the DOM API and other interfaces to work around the hassles that accompany Flash content, in particular version detection.

Given production-ready Flash content and the current swfobject.js file on the web server, a developer need only call the swfobject.js file via a script element in the head of the document, insert a line of markup into the production document, and follow that markup with another brief fragment of JavaScript that creates an application-specific SWFObject object. That object in its turn modifies the preceding markup to create and populate the element that contains the desired Flash presentation.

It is also possible to write your own standards-compliant object markup and execute the SWFObject script solely to gain access to version detection and other features.

Note

As you’ll see near the end of the chapter, HTML5 is introducing new solutions to address audio and video more directly, without Flash.

If you have a bare video file that needs to be placed online and you choose Flash as your playback environment, ...

Get HTML & CSS: The Good Parts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.