Using Flash in a Drupal Theme - flash node


By matt - Posted on 22 July 2008

One of the reasons I like doing web development is because it doesn't matter how much you understand you can still be sure you are only grasping the tip of the ice burg. There is just so much to learn, and many ways to skin a cat.

The idea behind this blog is to share the challenges that confront me, and in particular to give answers to questions that took the most time to get. This brings me to the topic of this post - how to get flash working in a Drupal6 theme...

This took a while for me to figure out. I thought it would be easy - just make the flash, chuck the .swf in your image folder in the design and then throw the flash HTML into page.tpl.php. Well... you can do it this way but you may find your movie only loads on the first page that the user hits, then on all subsequent pages a user gets 'movie not loaded' (if you right click on where the swf should be). This is because the theme has not had to reload to be displayed on subsequent visits.

After banging my head against various actionscript code for hours I gave up only to find later there is actually a very easy solution in the form of a handy module called 'flash node'. With Flash node swf files don't have to live in your theme - they are made part of your content. Just install and enable the module and you now have a Flash content type.

Simply upload your swf file into your database and put the following peice of code in your page.tpl.php where you want it to appear: <?php
print flashnode_content(array('nid' => nnn));
?>

<?php
print flashnode_content(array('nid' => nnn));
?>

where nnn is the node number (your new flash content will have been assigned a node like any other piece of content). You don't even have to publish it for it to work. Probably best that you change the permissions on this piece of content as you don't want your content authors deleting it accidentally!

Flash node even works with mp3's. For more information see flash node at drupal.org.