In the world of Flash interactvities and multimedia applications it is always important to let the user know what is happening when the application needs to be paused while a fairly large amount of data is being loaded. To do that nothing's best than a nice preloading system.
Up to Flash MX 2004 there was no easy way to create preloaders, a bit of fiddling was necessary to achieve a decent result. The lack of methods for preloading assets in Flash was so obvious that on April 16, 2003 Colin Moock submitted a petition to Macromedia for a better preloading API.
It seems that Macromedia took that request into account since with Flash MX 2004 and Flash player 7, the MovieClipLoader class came to the rescue. The MovieClipLoader class is very useful to control the loading of SWF, GIF, PNG and JPG files into Movie clips. We are going to examine this class, its methods and properties in more detail in the following tutorial.
Overview
A bit of theory
The MovieClipLoader class gives us full control on the loading of SWF and pictures, from the start to the initialization of the loaded asset.
The
MovieClipLoader class is implemented, as we will see on the next page, by registering a listener object that will receive notifications when a MovieClipLoader event handler is invoked.
The MovieClipLoader class is composed of 5 event methods that are used to monitor the loading of an asset from start to finish. These 5 event methods are
onLoadStart,
onLoadProgress,
onLoadComplete,
onLoadInit and
onLoadError. The beauty of these events is that they are giving us precious information at some key points of the loading and we can use that information to create an advanced preloading system (
see my tutorial on creating a preloader). Let's have a look at the picture below :
1. onLoadstart is invoked as soon
as the first byte of data of the asset being loaded has been written on the hard drive. The parameter returns the name of the container receiving the loaded asset, that parameter is optional.
2. onLoadProgress is invoked every time the loading content is written to the hard drive during the loading process. returns the number of bytes loaded since the loading started and returns the total size of the asset being loaded, again the first parameter is optional.
3. onLoadCompleteis invoked as soon
as the last byte of data of the asset being loaded has been written on the hard drive. Both parameters are optional.
4. onLoadInit is invoked as soon as the loaded asset has been initialized and is ready for action.
5. onLoadError is invoked if the server is down, the file is not found, or a security violation occurs.
More methods
Along with these 5 event methods, the MovieClipLoader class makes use of 5 methods that need to be mentioned :
- loadClip We use this method to load the SWf or picture
- getProgressReturns the number of bytes loaded and the total number of bytes of a file that is being loaded
- addListener Registers an object to receive notification when a MovieClipLoader event handler is invoked.
- removeListener Removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked.
- unloadClip Removes a movie clip that was loaded by using MovieClipLoader.loadClip().
Continue to next page...