What's New in Director 8.5 > Controlling the 3D World > 3D Lingo events |  |

3D Lingo events

Event handling lets you use the `registerForEvent` command to specify a handler to run when a particular event occurs within a specific cast member. With the `registerForEvent` command you specify the type of event that will trigger the handler, the handler name, and the script object that contains the handler. The script object can be a child script, an instance of a behavior attached to a sprite, or any other script. If the script object isn't specified, the handler is called in the first movie script in which it is found.

Use these commands to set up event handling:

Command | Description | Returns
--- | --- | ---
`registerForEvent(``eventName``,``handlerName``,``scriptInstance``,` `model``)` | The event `eventName` is one of the following: `#collideAny`: Called when any collision occurs. `#collideWith`: Called when a collision with a specific model occurs and implicitly registered when `setCollisionCallback(...)` is called. Equivalent to calling`model.collision.setCollisionCallback`.

`#timeMS`: Sets up a time-based simulation callback using the format `registerForEvent(timeMS,` `handlerName``,` `scriptInstance``)``begin``,` `period``,` `repetitions`.

The `begin` and `period` arguments are in milliseconds. If `repetitions` is set to `0`, the simulation continues indefinitely.

`#animationStarted`: Called whenever a keyFrame or bones motion begins.

`#animationEnded`: Called whenever a keyFrame or bones motion ends.

Any user-defined symbol: Registers to receive any user-defined event sent from a SendEvent call.

`TRUE (1)` if the operation succeeds.

`FALSE (0)` if the operation fails.

`unregisterAllEvents()_` | Unregisters all events. | Nothing. A Lingo error is generated if the operation fails.
`sendEvent(``eventName``,` `arg1``,``arg2...``)` | Sends an event named `eventName` to all scripts registered to receive it. Similar to `sendAllSprites()` except that the event is delivered only to scripts that are registered to receive it. | Nothing. A Lingo error is generated if the operation fails.