FileLoader: A Flash Preloader & Container File (with Cache Buster Option)

Recently, I had a client whose server had its own cache that only cleared once a day, which ended up posing problems for updating content, as the server cache would either needed to be flushed, or we’d just have to wait it out and wait for the cache to clear on its own.  The content I was working on was a Flash file, so rather than having to flush the server cache every time I made an update, I came up with another solution for the Flash file.

The solution was to make a “container” SWF file that would load in the actual content for the page.  This was nice because the container ended up also acting as a preloader for the main content.  All I had to do in the container file was to append a query string to the end of the content to load in (i.e. “photo.jpg?id=12345678”), which effectively acted as a “cache buster” that would make the browser and server think it was loading a new file each time the page was loaded.

The result was this little nugget of Flash goodness: FileLoader.

I polished up the container file I made in my solution above, adding in a couple of customizable variables, and am making it freely available for download.

Version Information:

  • Version: 1.0
  • Release Date: 1/12/11

Download:

Like what you see? Want to use FileLoader with your own Flash projects? Click the button below to download the most recent version of FileLoader, including a demo file with full instructions.

Fork Project on GitHub

License:

Creative Commons License

FileLoader is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License, and is free to use. Links back to hesslerdesign.com are always appreciated. Permissions beyond the scope of this license may be available by submitting a Contact Request.

Description:

FileLoader is a simple, lightweight, easy-to-implement FLA/SWF file that acts as a preloader and container for files. It is made to load a specified URL, can enable “cache busting”, and provides the ability to change the hex color of the preloader and text. It can load any type of file that the built-in Loader class loads (SWF, JPG, PNG, GIF).

Example:

Instructions:

To use this file, simply update any/all of the customizable variables located on the aptly-named “Customizable Variables” layer (in .fla file). These variables include:

  1. contentURL (String): URL path of the content you wish to load into FileLoader. (Default = “”)
  2. tintHex (uint): Hex value to tint the preloader and error message. (Default = “0x000000”)
  3. cacheBuster (Boolean): Enables/Disables “cache busting” on your content. (Default = “false”)

Once the variables are updated, just export the SWF and it’s ready to be embedded into your HTML page for the web.

Notes:

  1. FileLoader is set up to resize itself to 100% of the stage width and height, making it flexible to be used at any size. This means you don’t have to worry about changing the dimensions of the file, and when embedding this file into your HTML page, you can specify any width and height you wish. The Preloader and Load Error (if applicable) will automatically center themselves to the stage. The content, however, has no special positioning logic, and will be placed at the (0,0) point of the stage. Thus, it is intended that this file will be embedded at the exact size of the content you’re loading into it, as this file is only intended to be a preloader and container for the contents of one file.
  2. The Preloader and Load Error elements (where applicable) are automatically added to and removed from the file when needed. Your content will automatically be placed into the file when it’s loaded, and be the only item on the stage at that point. You don’t have to do anything special to get your content to display other than specifying a valid content URL.
  3. When you’re ready to post the files to your website, just make sure you upload this file along with the content it loads. Also, make sure your pathing is set up appropriately for the content URL or your content may not load correctly.
  4. If you update or change any of the MovieClips in the library, or update, append or change any of the code in the main Actions layer, this file may break. If you know what you’re doing with Flash and ActionScript, you shouldn’t have any problem figuring out how things work and can be edited. If you’re a beginner or novice, you may have a harder time editing. With that said, edit the non-customizable elements at your own risk.
  5. If the “cacheBuster” variable is set to “true”, a random 8-digit ID will be appended as a query string to the “contentURL” variable (i.e. “photo.jpg?id=12345678“). When the cache buster is enabled, it will force the FileLoader to load a fresh version of the content URL each time it is loaded. This is helpful if you are posting your Flash content on a server with its own cache settings that would result in updated content not being immediately visible until the server cache clears. If this variable is set to “false”, no ID will be appended to the content URL, and the loaded content will be cached as normal.
  6. Important: Use the cache busting sparingly and only when necessary, as it may end up bogging down the server with unnecessary calls to the server to reload the content.

One Response to this post:

Leave a Comment