Flash Lite 2.x and 3.0 ActionScript Language Reference

onLoad (MovieClip.onLoad handler)

onLoad = function() {}

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.

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) or the MovieClipLoader class instead of this handler. Unlike MovieClip.onLoad, the other handlers are invoked when any movie clip loads.

Example

This example shows you how to use the onLoad event handler in an ActionScript 2.0 class definition that extends the MovieClip class. First, create a class file named Oval.as and define a class method named onLoad() and make sure that the class file is placed in the proper class path:

// contents of Oval.as
class Oval extends MovieClip{
    public function onLoad () {
        trace ("onLoad called");
    }
}

Second, create a movie clip symbol in your library and name it Oval. Context-click (usually right-click) on the symbol in the Library panel and select Linkage... from the pop-up menu. Click on "Export for ActionScript" and fill in the "Identifier" and "ActionScript 2.0 Class" fields with the word "Oval" (no quotes). Leave "Export in First Frame" checked and click OK.

Third, go to the first frame of your file and enter the following code in the Actions Panel:

var myOval:Oval = Oval(attachMovie("Oval","Oval_1",1));

Finally, do a test movie, and you should see the output text "onLoad called".

See also

loadMovie (MovieClip.loadMovie method), onClipEvent handler, MovieClipLoader