Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > MovieClip > 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.
You use this handler 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, you must use onClipEvent(load) or the MovieClipLoader class instead of this handlerl; for example, when you use MovieClip.loadMovie() to load a SWF file dynamically. Unlike MovieClip.onLoad, the other handlers are invoked when any movie clip loads.
Availability: ActionScript 1.0; Flash Player 6
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(). Then ensure that the class file is placed in the proper class path, as in the following example:
// 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 the Export for ActionScript option and enter Oval in the Identifier and ActionScript 2.0 Class fields. Leave the "Export in First Frame" option selected, 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".
loadMovie (MovieClip.loadMovie method), onClipEvent handler, MovieClipLoader
Version 8
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00002494.html
Comments
Jim Foy said on Feb 15, 2006 at 8:58 AM :