
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Copying Movie Clip Event Handlers
|
239
When we play our movie, the execution order is as follows:
= = = = = = = =FRAME 1= = = = = = =
1) Main timeline code executed
2) load handler executed
3) Clip-internal code, frame 1, executed
= = = = = = = =FRAME 2= = = = = = =
1) enterFrame handler executed
2) Clip-internal code, frame 2, executed
3) Main timeline code executed
= = = = = = = =FRAME 3= = = = = = =
1) enterFrame handler executed
2) Clip-internal code, frame 3, executed
3) Main timeline code executed
= = = = = = = =FRAME 4= = = = = = =
1) unload handler executed
2) Main timeline code executed
The execution order of the code in our sample movie demonstrates some important
rules of thumb to remember when coding with movie clip event handlers:
• Code in a load handler is executed before internal clip code, so a load handler
can be used to initialize variables that are used immediately on frame 1 of its
associated clip, but only if the handler is created with the onClipEvent( ) syntax.
See MovieClip.onLoad( ) in the Language Reference for further details.
• Before a movie clip is instantiated on a frame, the code of that frame is executed.
Therefore, user-defined variables and functions in a movie clip are not available
to any code on its parent timeline until the frame after the clip first appears ...