jQuery plugin and Drupal module for embedding Flash files

Mar 18 2009

Today, Palantir.net is releasing several module that we built as part of our client work. One of these modules is the SWF Embed module. With this module, developers can create tools that include flash objects.

This module makes use of both PHP code and JavaScript code in order to provide robust Flash integration used in projects like the Flashy Drupal video player. But from a developer's point of view, all you need to do to add Flash support is create an object and theme it. The SWF Embed handbook page describes this process in detail (not that there is a lot to describe).

But there is a hidden gem in there that may come in handy for your non-Drupal sites (if you believe in such a thing). We developed a jQuery plugin, jquery.swfobject.js, that can be used to embed any flash media into a site using just jQuery and this plugin. At its simplest, this code can be called like this:

$('#some-element').swfembed('http://example.com/path/to/file.swf');

The code above will add a Flash object inside of the element with the id some-element.

Of course, most flash applications aren't that straightforward. They need parameters. They need flash vars. They need a height and a width... and a location to redirect users who need to install flash.

This sort of data can be passed in using an optional second parameter for $.swfembed(). This second parameter is a map of options.

The following options are supported:

  • width: The width of the object
  • height: The height of the object
  • mimeType: The object's MIME type (default: "application/x-shockwave-flash")
  • params: An object containing params (e.g. {'allowFullScreen': 'true'})
  • flashvars: An object containing flashvars (Flash-specific variables) (e.g. {'myVar': 'Foo'})
  • version: The minimal Flash player version necessary to use this object.
  • expressInstall: The URL to an express install page
  • pluginspage: The URL to download Flash Player (default: "http://www.adobe.com/go/getflashplayer")

Want to start using this tool? you can get it from Drupal's CVS repository at http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/swfembed/.



comments powered by Disqus