View comments | RSS feed

MovieClipLoader.onLoadProgress

Availability

Flash Player 7.

Usage

listenerObject.onLoadProgress = 
   function([target_mc:Object [, loadedBytes:Number [, totalBytes:Number ] ] ] ) {
   // your statements here
}

Parameters

listenerObject A listener object that was added using MovieClipLoader.addListener().

target_mc A movie clip loaded by a MovieClipLoader.loadClip() method. This parameter is optional.

loadedBytes The number of bytes that had been loaded when the listener was invoked.

totalBytes The total number of bytes in the file being loaded.

Returns

Nothing.

Description

Listener; invoked every time the loading content is written to disk during the loading process (that is, between MovieClipLoader.onLoadStart and MovieClipLoader.onLoadComplete). You can use this method to display information about the progress of the download, using the loadedBytes and totalBytes parameters.

The value for target_mc identifies the movie clip this call is being made for. This is useful if you are loading multiple files with the same set of listeners. This optional parameter is passed to your ActionScript.

Example

The following example creates a progress bar using the Drawing API. The progress bar displays the loading progress of an image using the onLoadProgress listener. When the image finishes loading, the progress bar is removed from the Stage. You must replace the URL parameter of the image_mcl.loadClip() command so that the parameter refers to a valid JPEG file using HTTP. If you attempt to use this example to load a local file that resides on your hard disk, this example will not work properly because, in test movie mode, Flash Player loads local files in their entirety. Add the following ActionScript to your FLA or AS file:

this.createEmptyMovieClip("progressBar_mc", 0);
progressBar_mc.createEmptyMovieClip("bar_mc", 1);
progressBar_mc.createEmptyMovieClip("stroke_mc", 2);
with (progressBar_mc.stroke_mc) {
   lineStyle(0, 0x000000);
   moveTo(0, 0);
   lineTo(100, 0);
   lineTo(100, 10);
   lineTo(0, 10);
   lineTo(0, 0);
}
with (progressBar_mc.bar_mc) {
   beginFill(0xFF0000, 100);
   moveTo(0, 0);
   lineTo(100, 0);
   lineTo(100, 10);
   lineTo(0, 10);
   lineTo(0, 0);
   endFill();
   _xscale = 0;
}
progressBar_mc._x = 2;
progressBar_mc._y = 2;
//
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
   progressBar_mc.bar_mc._xscale = 0;
};
mclListener.onLoadProgress = function(target_mc:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
   progressBar_mc.bar_mc._xscale = Math.round(bytesLoaded/bytesTotal*100);
};
mclListener.onLoadComplete = function(target_mc:MovieClip) {
   progressBar_mc.removeMovieClip();
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
   target_mc._height = 320;
   target_mc._width = 240;
};
this.createEmptyMovieClip("image_mc", 100);
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip("[place a valid URL pointing to a JPEG file here]", image_mc);

See also

MovieClipLoader.getProgress()

Comments


Spen said on Nov 27, 2004 at 6:39 PM :
It might be worth pointing out that onLoadProgress events are not broadcast when using Test Movie mode in Flash. You have to go through a browser. Please correct me if I'm wrong. I just spent 4 hours trying to figure out why this wasn't working. Macromedia please please document issues like this.
boldhead said on Nov 27, 2004 at 7:51 PM :
If that is right, I can stop wondering why this was the only thing I couldn't figure out how to get to work! Is this a bug in the SA-player? And, yes, why isn't this documentet?
S. Jackson said on Jan 17, 2005 at 2:36 PM :
Yes, this is significant enough that it warrants updating the docs.
Francis Cheng said on Jan 17, 2005 at 3:01 PM :
Hi,

Sorry you lost time trying to get this to work in test movie mode. There is mention of this issue in the Example section:

"If you attempt to use this example to load a local file that resides on your hard disk, this example will not work properly because, in test movie mode, Flash Player loads local files in their entirety."

I'll promote it to a Note: in the Description section to make it easier to see.
No screen name said on Apr 8, 2005 at 8:08 PM :
Every time i use onLoadProgress, I get a script error warning from IE and Safari telling me that Flash Player 7 is having script issues and recommends aborting the script. What's the cause of that, and more importantly, what's the solution??
Ɓukasz Grela said on Apr 15, 2005 at 4:40 AM :
I think that You have XP with SP2 installed, it some security settings
jaseinatl@gmail.com said on Jun 8, 2005 at 6:15 PM :
I tried to copy the contents exactly as they were given in the example. I replaced the quoted string with my local URL and selected Publish>html from from the file menu.

NO RESULTS. It loaded Firefox (my default browser) and displayed a blank page.

Just thought I'd tell ya...there are much better examples to be used for MCL, but for now, I'm going back to LoadVars and onEnterFrame loaders.
No screen name said on Sep 27, 2005 at 9:00 AM :
I used this, with good results. One problem. My swf has 2 scenes, this code is in the 2nd scene. the linestyle for progressBar_mc.stroke_mc is rendered in scene 1. once i went to scene 2 then back to scene 1, it was cleared. Was very annoying to have a box in the middle of the main movie

The way i fixed it was to make the linestyle transparent (progressBar_mc.stroke_mc) {
lineStyle(0, 0x000000, 0);

works fine now.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001581.html