Home Services Industries Showcase Library People How to Store .swf Files in Any Directory You Want...

The Problem

A common misperception among Flash developers is that .swf files (the deployed Flash movie files) with HTML links (for example, a nav bar) must be in the same directory as the files that call them. This leads to very flat, poorly organized directory structures.

The Solution

The solution is simple... You simply need to use the often-overlooked <base href="pageURL"> tag in the <head> section of your HTML document. For some strange reason, Flash will interpret the links one way if <base href...> exists, and another way if it doesn't exist.

The way that <base href="pageURL"> works is simple. Simply substitute the actual URL of your page in lieu of "pageURL." For example the tag for this page looks like this:

<base href="http://www.slicksurface.com/library/flash/basehref.php">

Usually this tag is only used if you want to deploy a page in one place and have it act as if it is located somewhere else. However, good rigorous coding with explicity declare the location of the document.

PHP and SSI Scripting for <base href...>

It may seem like a lot of trouble to put the URL for each page in the header of each page, but if you're working with PHP or SSI (.shtml) pages, you can put a consistent tag in the top of the document that will always work, even if you move the page or serve it from a different domain.

First, let's examine the PHP that is used for this page. At the top of this page is:

<base href="<?php echo"$SCRIPT_URI" ?>">

When the page is loaded and served, the server changes this to the correct URL shown above. $SCRIPT_URI is an environment variable that has the full URL for the page.

The same thing can be done in SSI, but the syntax is simply a little different:

<base href="<!--#echo var="SCRIPT_URI"-->">

If your server does not support the SCRIPT_URI environment variable, you can use a combination of the SERVER_NAME and DOCUMENT_URI environment variables, as shown below:

<base href="http://<!--#echo var="SERVER_NAME"--><!--#echo var="DOCUMENT_URI"-->">