MovieClipLoader Class in Flash 8/Flash MX 2004

MovieClipLoader Class provides you with a rich set of methods that allows you to load an external JPEG image/Swf on a movieclip.

The main advantage of using MovieClipLoader over other methods for loading external Images is:

  • Facility of showing Progress of the Loading Image
  • Showing custom message in case there is any error while loading the image/swf

Methods of MovieClipLoader Class:

  • .loadClip(url,target)
    This method is responsible for loading the external image file. The url will the path to the external image file. The target will be the movieclip name where you will load the image.
    NOTE: The target is compulsory.
  • .getProgress(target movieclip)
    This method return you the bytes loaded. But to check the actual size loaded you will have to use bytesLoaded() and bytesTotal() method of getProgress. bytesTotal gives you the total size of the image in bytes and bytesLoaded gives you the currently loaded bytes. You can use only this method only after calling loadClip method.
  • .unloadClip()
    Removes the movieclip on which the image was loaded. But technically it doesn’t works all the time.
  • .addListener()
    This forms the heart of the MovieClipLoader Class, to use all the events of the MovieClipLoader class you will have to define an listener object for the MovieClipLoader class
  • .removeListener()
    This method removes the MovieClipLoader listener object from the memory

Your email:

 


Event Listener in MovieClipLoader:

  • onLoadComplete()
    This event listener gets called when the image is successfully loaded i.e it is completely downloaded on the client machine

Example on onLoadComplete:

var my_mcl = new MovieClipLoader();
myListener = new Object();
my_mcl.addListener(myListener);
 
myListener.onLoadComplete = function ()
{
trace("Image Successfully Loaded");
}
  • onLoadInit()
    This is the first event listener that gets called whenever the image is loaded using loadCLip method. Here you can perform all initial operation before showing the loaded image. The initial operation can be resizing the movieclip on which the image is loaded

Example on onLoadInit:

var my_mcl = new MovieClipLoader();
myListener = new Object();
my_mcl.addListener(myListener);
 
myListener.onLoadInit = function (load_mc)
{
trace("Perform Initial Operation");
load_mc._width = x px;
 
}
  • onLoadError()
    This event listener that gets fired when there is some error loading the external image. This event can be useful in showing some error message to the user.

Example on onLoadError:

var my_mcl = new MovieClipLoader();
myListener = new Object();
my_mcl.addListener(myListener);
 
myListener.onLoadError = function (load_mc)
{
trace("Error Loading Image Please Try Again");
}
  • onLoadProgress()
    This event listener is useful in checking the progress of the image getting loaded

Important Note:
There is a strange behavior in the MovieClipLoader class where regards to image caching. Once the MovieClipLoader class is initialized it stays in the memory even after calling removeListener and unloadClip method. To solve this problem refer to this link : Solution to MovieClipLoader Caching Issue

Custom Search


Popular Articles:

  1. No comments yet.
  1. No trackbacks yet.