15.10. Monitoring Load Progress Without a Progress Bar Component

Problem

You want to monitor the load progress of an asset without having to use the Progress Bar component.

Solution

Create a movie clip and define an onEnterFrame( ) method that monitors the load progress of the asset, or use an interval function. Alternatively, you can create a custom LoadMonitor class.

Discussion

The Progress Bar component is a handy, pre-built resource for graphically representing the progress of an operation, such as asset loading. However, the Progress Bar component is overkill if you merely want to monitor the download progress in the background in order to trigger other actions when appropriate.

You can use a movie clip with an onEnterFrame( ) method to monitor the load progress of an asset. Within the onEnterFrame( ) method, you should continually check the percentage of the asset that has loaded.

// Create a movie clip and begin loading a .swf file into it.
_root.createEmptyMovieClip("swfHolder", 1);
swfHolder.loadMovie("externalSWF.swf");

// Create a movie clip to monitor the load progress.
_root.createEmptyMovieClip("loadMonitorMc", 2);

// Define an onEnterFrame(  ) method for the monitor movie clip.
loadMonitorMc.onEnterFrame = function (  ) {

  // Execute trace(  ) once the .swf file has finished loading.
  if (_root.swfHolder.isLoaded) {
    trace("SWF has loaded");
  }
};

Or, you can achieve similar results using an interval function instead of a movie clip:

// Create a movie clip and begin loading a 

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.