AddThis Social Bookmark Button
 Preloading movies and pictures with the MovieClipLoader class (part 1)

download source files download source files

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([target_mc:MovieClip]) is invoked as soon as the first byte of data of the asset being loaded has been written on the hard drive. The parameter target_mc returns the name of the container receiving the loaded asset, that parameter is optional.

2. onLoadProgress([target_mc:MovieClip], loadedBytes:Number, totalBytes:Number) is invoked every time the loading content is written to the hard drive during the loading process. loadedBytes returns the number of bytes loaded since the loading started and totalBytes returns the total size of the asset being loaded, again the first parameter is optional.

3. onLoadComplete([target_mc:MovieClip], [httpStatus:Number]) is 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 ([target_mc:MovieClip]) is invoked as soon as the loaded asset has been initialized and is ready for action.

5. onLoadError(target_mc:MovieClip, errorCode:String, [httpStatus:Number]) 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(url:String, target:Object) We use this method to load the SWf or picture

- getProgress(target:Object) Returns the number of bytes loaded and the total number of bytes of a file that is being loaded

- addListener(listener:Object) Registers an object to receive notification when a MovieClipLoader event handler is invoked.

- removeListener(listener:Object) Removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked.

- unloadClip(target:Object) Removes a movie clip that was loaded by using MovieClipLoader.loadClip().

Continue to next page...
AddThis Social Bookmark Button
If you think this page is providing useful information, don't hesitate to leave a comment.
flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved