Tutorial details:
Written by: Jesse Stratford
Time: 15 minutes
Difficulty Level: Intermediate
Requirements: Flash 5.
Topics Covered: ifFrameLoaded, goto, set variables, dynamic text fields, movieClip properties.
Assumed Knowledge: Instances, Paths, basically all the Beginner level stuff.

Click here to download the source for this tutorial. (Flash 5, PC Zip file).

(The 'X' graphic in this file is copyright to me, Jesse Stratford, one of my brief toys with 3D rendering. You can download it here if you want it for personal use. 1024 x 768 )

In this tutorial we will discuss (or I will discuss) preloaders in Flash 5. One of the greatest benefits of Flash 5 is that it is self-aware. By this I mean that a flash file knows how big it is (in bytes, frames, time, etc), and knows where elements are in relation to itself. This allows us to do various things which, though they were possible in Flash 4, took a lot of effort.

Before I teach you about percentage preloaders, we've got to have a look at the basic preloader mechanism. If you've made a preloader before, you can skip this bit: I assume nothing.

A preloader is a buffering mechanism: it allows us to load up some of our content before we begin playing our flash file, to ensure smooth streaming and correct timing. I must emphasize the word some: personally I feel that Flash is a streaming medium and as such it should have as much streaming content as possible, thus I am not keen on 5Mb sites who preload the whole thing before it starts. That's a waste of my time and bandwidth. If you're going to make huge sites, I say make them hierarchical so that you can load up content when and more importantly if the user wishes to see it. Now, with the rant out of the way, let's move on.

The basic preloader in Flash 5 has not changed from Flash 4. You will see other ways to do it using onFrameEnter and the like but I still like the old way. Your basic preloader goes in a scene of its own before the main content scene, (you can move Scenes around using the object inspector, so don't worry if you're made your content and left the preloader to last). The preloader scene has 2 frames with the following actions:

Frame 1

ifFrameLoaded ("Scene 2", 1) {
 gotoAndPlay ("Scene 2", 1);
}

Frame 2

gotoAndPlay (1);

This example is for a SWF with 2 scenes, named Scene1 and Scene2, where most of the content is in frame 1 of Scene2. Thus we buffer up to (and including) the frame with most of the content, then we continue. The code above is pretty self-explanatory so I wont go into detail about it. Over the page we discuss the percentage calculator...