Unfortunately with the internet as it is, with 56k modems being so slow to download files, and even cable/dsl limiting how much information we can get quickly, we need to prepare our sites to play properly instead of breaking when loading. A Flash movie that isn't loaded and is forced to play, will break. It will stop, and often crashes.
To keep this from happening, we need to check to see that enough information is loaded into our movie for it to play properly. With actionscripting, we can do that. This is called preloading. It is basically just a loop that plays until our movie is ready to play and then it will end and our movie starts. Sometimes people make games for their users to play when waiting if it will take a long time.
Others just put up the words,"loading..." and the user must wait. It is possible to test loading in the Flash environment when using control/test Movie. You just turn on your Bandwidth Profiler under the view menu. Then you select a bandwidth setting (the size of your pipe: loading ability) from the Debug menu (56k, 28.8, or set your own in the custom settings to make a Cable/DSL setting). Now choose View/Show Streaming and you can see it load and get a feel for how long it will take.
Cable settings should be around: 90,000 bytes per sec.
(1,000,000 bits/sec)
56K: 4800 bytes per second
You can check to see if things are loaded with the following:
movieClip.getBytesLoaded and movieClip.getBytesTotal.
Here is a two frame loop example that goes to a new scene when loaded called "main".
Frame 1 action:
btload = _root.getBytesLoaded();
totbt = _root.getBytesTotal();
Frame 2 action:
if (btload>=totbt) {
gotoAndPlay ("main", 1);
} else {
gotoAndPlay (1);
}
Keep in mind that you don't always have to load the entire movie before it starts playing. You could just load a percentage of the movie (say 80%) and then have it play. Flash streams, so the rest will load. You just don't want it to crash if it doesn't load fast enough for the users connection. You could try:
Frame 1 action:
btload = _root.getBytesLoaded();
totbt = _root.getBytesTotal();
Frame 2 action:
percentload=Math.round(_root.getBytesLoaded()/_root.getBytesTotal()*100)
if
(percentload>=80){
gotoAndPlay ("main", 1);
} else {
gotoAndPlay (1);
}
So using the testing environment in Test Movie is key to testing for loading. Use the Bandwidth Profiler to see how things are loading.
download the basic preloader file
download some really excellent preloaders (includes functions, preloading external jpgs, etc: from Flash MX Actionscript Bible)
download a bunch of preloader files