nwebb banner

   hometutorialsworkphotosflash

 Recommended
 
 Tutorials


Tutorial details: Using the MovieClipLoader API
Difficulty Level: Intermediate
Requirements: Flash MX 2004
Assumed Knowledge: Familiarity with basic actionscript (v1)
File(s) to Download: MCL_tutorial.zip
Online Example: MovieClipLoader




Flash MX 2004 introduces MovieClipLoader

If you have ever tried to load an external jpeg or swf in to a flash movie, it is likely you will have encountered a situation where you need to trigger an event based upon completion of that loading process.

Loading external data of any kind in to Flash is never instantaneous, therefore it usually gives rise to the need for some sort of checking process - usually in the form of a preloader.

The MovieClipLoader API (Applications Programming Interface) takes away much of the necessary work involved in loading images and swfs in to our Flash movies, and allows us to be notified about the various stages of loading, ultimately giving us more control over our movie, and helping us cut down on the amount of code we need to write.

We can use a single instance of the MovieClipLoader class to load one or more files in to a single movieclip/level, or create a different MCL instance for each file we load.

I have decided to split the subject up in to two seperate tutorials. The first will introduce you to basic MCL usage, and the second will show you how to use a single MovieClipLoader instance to load content in to multiple (duplicated) movie clips, and will employ the use of a listener object. It is possible to use MCL without the need for a listener, and as some of you will not be familiar with how they work you may find it easier to learn about the MovieClipLoader if we ignore using a listener for the time being.

With that said, let's look at what makes the MovieClipLoader class so useful - callback functions. Callbacks are the 'internal organs' of tha MCL class - they are what provide us with the information on the status of the files being downloaded. There are 7 callbacks in all, 5 of them give us infomation about various stages of the loading process. The other two deal with unloading and errors. Let's take a very brief look at them before we proceed:

MovieClipLoader callbacks:

  • MovieClipLoader.onLoadStart() - invoked when loading begins.
  • MovieClipLoader.onLoadProgress() - invoked as the loading process progresses.
  • MovieClipLoader.getProgress() - progress of the downloaded file(s).
  • MovieClipLoader.onLoadInit() - invoked after the actions in first frame of clip have executed.
  • MovieClipLoader.onLoadComplete() - invoked when the entire downloaded file has been written to disk.
  • MovieClipLoader.onLoadError() - invoked if the clip cannot be loaded.
  • MovieClipLoader.unloadClip() - remove movies/images loaded with this method or cancels a load operation in progress.

Part: 1 2 3 4