User Guide

MovieClip.onLoad 559
MovieClip.onLoad
Availability
Flash Player 6.
Usage
my_mc.onLoad = function() {
// your statements here
}
Parameters
None.
Returns
Nothing.
Description
Event handler; invoked when the movie clip is instantiated and appears in the Timeline. You
must define a function that executes when the event handler is invoked. You can define the
function on the Timeline or in a class file that extends the MovieClip class or is linked to a symbol
in the library. For more information, see “Assigning a class to a movie clip symbol” in Using
ActionScript in Flash.
This handler can be used only with movie clips for which you have a symbol in the library that is
associated with a class. If you want an event handler to be invoked when a specific movie clip
loads, for example when you use
MovieClip.loadMovie() to load a SWF file dynamically, you
must use
onClipEvent(load) instead of this handler. The latter handler is invoked when any
movie clip loads.
Example
The following example illustrates one way to use MovieClip.onLoad() with setInterval() to
check that a file has loaded into a movie clip thats created at runtime:
this.createEmptyMovieClip("tester_mc", 1);
tester_mc.loadMovie("http://www.yourserver.com/your_movie.swf");
function checkLoaded(target_mc:MovieClip) {
var pctLoaded:Number = target_mc.getBytesLoaded()/
target_mc.getBytesTotal()*100;
if (!isNaN(pctLoaded) && (pctLoaded>0)) {
target_mc.onLoad = doOnLoad;
trace("clearing interval");
clearInterval(myInterval);
}
}
var myInterval:Number = setInterval(checkLoaded, 100, tester_mc);
function doOnLoad() {
trace("movie loaded");
}