Awhile back, I wrote an installment of the "10 Minutes with Flash" series called "ActionScript You'll Never Have to Write Again" about writing a shell of a script and saving it for later use. I used a MovieClipLoader object for the example because it is something developers need frequently while developing for Flash Player 7. Today, we'll take the concept further by turning a modified version of the same script into a component that preloads external assets by incrementing a percentage value in a text field. That's rightit's a pre-loader. And once you build it, you'll never have to build it again.
The Movie Clip
First, we need a new file and a movie clip. (Components are really just movie clips that are compiled into self-contained .swc files.)
Launch Flash MX 2004 or Flash Pro and save a new document as The_Loader.fla.
Create a new Movie Clip symbol called The_Loader. (I just love it when things are totally obvious.)
To increment a percentage value in a text field, we need to add a text field to the movie clip.
Activate the Text tool and choose Dynamic from the Text type menu in the Property inspector.
Click on the Stage to create a dynamic text field. Drag the text field's handle to make it about two inches long.
With the field still selected, enter message_txt into the instance name field of the Property inspector.
Set the font for the text field to, let's say, 12 pt. Arial.
Save your work, but leave the file open.
I've got about eight minutes left.
Now that we have the text field ready, we can start writing the script for the pre-loader. So far, your file should match Figure 1.
Figure 1 The dawn of a new age...er...component.