You want to display the progress of an asset-loading operation using a progress bar.
Use the Progress Bar component.
The Progress Bar component is included in the Flash UI Components Set 2. You can download this components set for free from the Macromedia Flash Exchange at http://www.macromedia.com/exchange/flash/. The full URL is:
After downloading the components set, install it using the Macromedia Extension Manager (also a free download from the Flash Exchange). You have to restart Flash to see the new components. Once you restart Flash, you should see the Flash UI Components Set 2 option in the Components panel menu.
You can add a progress bar to a movie manually at authoring time, or you can add the Progress Bar component to the movie's Library and use the attachMovie( ) method to add the component to the movie at runtime:
_root.attachMovie("FProgressBarSymbol", "pBar", 1);
You should use the setLoadTarget( ) method of a progress bar instance to specify a movie clip or a sound that the component should monitor:
// This code configures a progress bar named soundPBar to monitor the load progress // of a sound named mySound_sound. soundPBar.setLoadTarget(mySound_sound); // This code configures a progress bar named jpegPBar to monitor the load progress of // a JPEG into a movie clip named myMovieClip_mc.imageHolder_mc. jpegPBar.setLoadTarget(myMovieClip_mc.imageHolder_mc);
Here is a complete example showing how to monitor the loading of an MP3:
// Include the Sound.as file from Chapter 13. #include "Sound.as" // Create the Sound object. mySound_sound = Sound.createNewSound( ); // Load an MP3 from the same directory as the Flash movie. Set streaming to false. mySound_sound.loadSound("myMP3.mp3", false); // Add the progress bar. _root.attachMovie("FProgressBarSymbol", "pBar", 1); // Set the progress bar to monitor the sound. pBar.setLoadTarget(mySound_sound);
The progress bar indicates the load progress each time a new chuck of data is received. The perceived smoothness of this depends on the connection speed and latency.
Recipe 15.11 and Recipe 15.12. See Recipe 15.10 for an alternative approach. You can also find other third-party progress bars by going to the Macromedia Flash Exchange (http://www.macromedia.com/exchange/flash) and searching for "Progress Bar."