Using Director > Writing Scripts with Lingo > Writing Lingo statements > Understanding the order of messages in a movie |  |

Understanding the order of messages in a movie

Director follows a definite order when sending messages about events that occur during the course of a movie.

When the movie first starts, events occur in the following order:

1 | `prepareMovie`
2 | `beginSprite`
| This event occurs when the playback head enters a sprite span.
3 | `prepareFrame`
| Immediately after the `prepareFrame` event, Director plays sounds, draws sprites, and performs any transitions or palette effects. This event occurs before the `enterFrame` event. An `on prepareFrame` handler is a good location for Lingo that you want to run before the frame draws.
4 | `startMovie`
| This event occurs in the first frame that plays.

When Director plays a frame, events occur in this order:

1 | `beginSprite`
| This event occurs only if new sprites begin in the frame.
2 | `stepFrame`
3 | `prepareFrame`
| Immediately after the `prepareFrame` event, Director plays sounds, draws sprites, and performs any transitions or palette effects. This event occurs before the `enterFrame` event.
4 | `enterFrame`
| After `enterFrame` and before `exitFrame`, Director handles any time delays required by the tempo setting, idle events, and keyboard and mouse events.
5 | `exitFrame`
6 | `endSprite`
| This event occurs only if the playback head exits a sprite in the frame.

When a movie stops, events occur in this order:

1 | `endSprite`
| This event occurs only if sprites currently exist in the movie.
2 | `stopMovie`