Events, messages, and handlers

A key component to creating powerful, useful scripts is an understanding of the concepts and functionality of events, messages, and handlers. Understanding the order in which events and messages are sent and received will help you determine exactly when specific scripts or parts of scripts should run. It will also help you debug scripts when specific actions are not occurring when you expect them to occur.

When a movie plays, the following occur:

  • Events occur in response to either a system or user-defined action.

  • Messages that correspond to these events are sent to the scripts in a movie.

  • Handlers within scripts contain the instructions that run when a specific message is received.

The name of an event corresponds to the name of the message it generates, and the handler that handles the event corresponds to both the event and the message. For example, when the event named mouseDown occurs, Director generates and sends to scripts a message named mouseDown, which would in turn be handled by a handler named mouseDown.