Flash 8 Cookbook | Page 3
20.4 Using a Progress Bar to Create a Graphical Preloader
You want to create a preloader that displays a progress bar indicating how much of the movie has loaded.
Modify the script from Recipe 20.2 to update the
_xscale property of a movie clip.
Although simply displaying a text-based progress indicator to the user (as in Recipe 20.3) may work for some applications, you'll more frequently want to display the progress in some sort of visual, animated manner. The most common such indicator is the progress bar. The progress bar, as the name suggests, is a rectangular shape (the bar) that indicates the progress as the file downloads. Although you can certainly make more elaborate sorts of indicators, the progress bar is the standard, and the basic principals in creating a basic progress bar apply to any progress indicator.
The script in Recipe 20.2 takes care of the majority of the work in creating any sort of basic preloaderÂgraphical or not. So you'll want to use the same script when adding a progress bar. However, you'll want to then add just one line of code (shown in boldface):
The new line of code tells Flash to adjust the scale in the x-direction for a movie clip called
mProgressBar such that it corresponds to the percentage of the file that has downloaded. Therefore, in order for the code to be effective, you must add a movie clip instance to the stage with an instance name of
mProgressBar. That movie clip ought to contain rectangular artwork that is left-aligned (meaning that the left edge of the rectangle shape is positioned at 0).
20.5 Creating Preloaders for Files with Exported Symbols
Your have a file that exports movie clips for ActionScript, and you want to add a preloader.
Use the same preloader principles discussed earlier in this chapter. In addition, uncheck the "Export in first frame" option for each exported movie clip within the library.
As you learned in Recipe 11.17, you can tell Flash to export a movie clip symbol even if it is not used at authoring time. That enables you to programmatically add instances of the movie clip using ActionScript. With a few simple movie clips exported for ActionScript, you won't likely notice any effect on the preloader. However, with many complex (particularly bitmap) movie clips that are exported for ActionScript, you may start to notice that the preloader doesn't appear immediately. It's possible that the preloader may not even appear until most of the file has downloaded. This is due to the default setting for movie clips exported for ActionScriptÂ they are set to export on the first frame. Thus every exported movie clip must download before Flash will play back even the first frame.
There is a relatively simple solution, however. Although the default setting is such that Flash-exported movie clips are exported on the first frame, you can tell Flash to use an alternate frame instead, with the following steps:
20.6 Creating Preloaders for Files with Components
Your movie contains components, and they prevent the preloader from appearing until the movie is almost entirely loaded.
Use the same principles as discussed in Recipe 20.5. Additionally, assign a frame other than 1 to the Export frame for classes field.
Components are special movie clips. And by default they are set to export on the first frame. That means that in order to properly preload an SWF that uses components you must employ the same strategy as is discussed in Recipe 20.5. However, in addition to the challenges presented by exported movie clips, components present a new challenge. Unlike standard exported movie clips, components are composed not only of graphical elements, but they consist also of ActionScript code. That ActionScript code is placed in special structures called classes, and those classes can account for rather significant file size. For example, the Loader component is approximately 27KB, almost all of which is due to the code in classes.
Like exported movie clips, classes export on the first frame by default. That means that all the code in all the classes used by an SWF must download before the first frame can play back, during which time the the user waits at a blank screen for seconds or even minutes. However, it's remarkably simple to adjust the export frame for the classes used by a Flash file:
In order for a component to properly work, you must make sure that the classes it requires are exported on a frame before the component is used.