Flash objects in Drupal
Mike Dixon
Its always the way, you go months without dealing with flash in Drupal when all of a sudden you get 5 people all asking the same thing, how do you deal with flash in Drupal.
We use the swftools module (http://drupal.org/project/swftools), these excellent modules give you an easy way to embed flash objects in your Drupal site. We will cover the basics of adding flash content to your Drupal site below.
- Download swftools from drupal.org (http://drupal.org/project/swftools). Extract the module and put it into your sites/all/modules/ directory -
- Download the swfobject javascript from http://blog.deconcept.com/swfobject/ - put this in your sites/all/modules/swftools/shared so you should end up with a the actual javascript file on a path of /sites/all/modules/swftools/shared/swfobject/swfobject.js.... Swfobject provides some excellent javascript that gets around the IE7 'click to activate' issues. Luckily the swftools module will abstract all this for you.
- Log onto your Drupal site and goto admin/build/modules. Enable the following modules - Swftools, SwfTools integration and swfobject.
- Goto admin/settings/filters - click on the filtered HTML and enable the swftools filter, then do the same for the full HTML filter. THis will allow you to use the swftools filter command in your nodes.
- Goto admin/media/swf/embed, expand the javascript embedding section and enable the swfobject option - this will tell swftools to embed your flash objects using the swfobject javascript.
You are now ready to start adding flash (swf files) to your Drupal site. You have 2 options, you can either add the flash using a PHP function call (say in your theme, a block, or a PHP formatted node) or by using the filter in one of your full or filtered HTML nodes.
The PHP method.
This method is useful if you want to add a flash object to your Drupal theme, or perhaps embed a flash object into a block. The function call is very simple - something like
print swf('mymovie.swf');
This will look for an swf file called mymovie.swf in your /files directory. You can get more advanced and pass additional paramaters into the swf function - the most typical being width and height, something like:
print swf('mymovie.swf', array('height'=>100, 'width'=>400));
This method can be used in any of your theme files (for example page.tpl.php), or in any block or node so long as the input format is set to PHP
The filter method
The second option is to embed the flash using a filter tag, the format of this tag is simply <swf file="mymovie.swf"> - so long as you enabled the filters as per step 4 above you should be able to add this tag to any of your nodes or blocks and have the swf file embedded for you
There is plenty more to the swftools suite of modules, but hopefully that should get you started adding flash to your Drupal site