Using loadMovie, loadSound or xmlData.load and the base parameter

Last modified: October 6, 2008 - 11:53

In order to keep the size of flash files down it is possible to separate a large file in to a number of parts and load the other sections as required using the loadMovie() function.

However, it is important to understand where the Flash player will look if you were to write loadMovie('submovie.swf', mc1). If the path to submovie.swf is not qualified then Flash assumes the file to be in the same location as the page that is loading, not the swf that is calling the submovie. This is important for Drupal since everything is loaded from index.php which is in the site root. Therefore a unqualified call to loadMovie() will look for the related file in the site root!

There are two solutions to this. The first is to use qualified paths in the ActionScript, so instead of loadMovie('submovie.swf', mc1) you would write loadMovie('/path/to/submovie.swf', mc1). That will work, but it can create problems if you move the file in the future or re-organise the site.

The second option is to use the base parameter. This tells the Flash player how to qualify the path. Flash node supports the base parameter and it can be altered under Advanced flash node options when editing a node. By default it is set to the site's Drupal file directory. This is assumed as the default since a common method is to use the upload module to add the sub-movies and that's where upload will store them. If you want to manually upload files, say via FTP, then you can put them anywhere that is accessible to your site and use the base parameter to point to them.

The advantage of using base is that it keeps the ActionScript code very simple and you can easily re-use the flash if the site is changed in the future.

The base parameter also works with functions like loadSound() for streaming audio.

There are some very simple examples of flash node using loadMovie() and loadSound() on my website.

Note - the site administrator can disable access to the Advanced flash node settings section, but the default parameter will still be passed to the Flash player so users can still use functions loadMovie() and loadSound(), provided they have a means of uploading the linked files.

The advantage of using the upload module to upload linked files is that if you later decide to delete the node then all the accompanying files are deleted too. It also lets you keep track of what other files are related to the "main" swf!

The same principle applies when loading xml files. If an unqualified path to the xml file is used in the ActionScript then Flash will use the base parameter again. This means it is actually very straightforward to implement features such as media players or image rotators using a combination of flash and xml via the flashnode and upload modules. This example shows an xml driven image rotator running on my site along with a more detailed description.

 
 

Drupal is a registered trademark of Dries Buytaert.