56
Chapter 3: Writing Scripts in Director
Parent script and child object basics
In Lingo, a parent script is a set of handlers and properties that define a child object; it is not a
child object itself. A child object is a self-contained, independent instance of a parent script.
Children of the same parent have identical handlers and properties, so child objects in the same
group can have similar responses to events and messages.
Typically, parent scripts are used to build child objects that make it easier to organize movie logic.
These child objects are especially useful when a movie requires the same logic to be run several
times concurrently with different parameters. You can also add a child object to a Sprite object’s
scriptInstanceList
or the Movie object’s
actorList
as a way to control animation.
Because all the child objects of the same parent script have identical handlers, those child objects
respond to events in similar ways. However, because each child object maintains independent
values for the properties defined in the parent script, each child object can behave differently than
its sibling objects—even though they are instances of the same parent script.
For example, you can create a parent script that defines child objects that are editable text fields,
each with its own property settings, text, and color, regardless of the other text fields’ settings.
By changing the values of properties in specific child objects, you can change any of these
characteristics as the movie plays without affecting the other child objects based on the same
parent script.
Similarly, a child object can have a property set to either
TRUE
or
FALSE
regardless of that
property’s setting in sibling child objects.
A parent script refers to the name of a script cast member that contains the property variables
and handlers. A child object created from a parent script is essentially a new instance of the script
cast member.
Differences between child objects and behaviors
While child objects and behaviors are similar in that they both can have multiple instances, they
have some important differences as well. The main difference between child objects and behaviors
is that behaviors are associated with locations in the Score because they are attached to sprites.
Behavior objects are automatically created from initializers stored in the Score as the playhead
moves from frame to frame and encounters sprites with attached behaviors. In contrast, child
objects from parent scripts must be created explicitly by a handler.
Behaviors and child objects differ in how they become associated with sprites. Director
automatically associates a behavior with the sprite that the behavior is attached to, but you must
explicitly associate a child object with a sprite. Child objects do not require sprite references and
exist only in memory.
Ancestor basics
Parent scripts can declare ancestors, which are additional scripts whose handlers and properties a
child object can call on and use.
Ancestor scripting lets you create a set of handlers and properties that you can use and reuse for
multiple parent scripts.
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...