Chapter 16
418
Parent script and child object basics
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’s
scriptInstanceList
or the
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.
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 don’t 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.
A parent script makes another parent script its ancestor by assigning the script to its
ancestor
property. For example, the following statement makes the script What_Everyone_Does an
ancestor to the parent script in which the statement occurs:
set ancestor to new(script "What_Everyone_Does")
Содержание DIRECTOR MX-USING DIRECTOR MX
Страница 1: ...Using Director MX Macromedia Director MX...
Страница 12: ...Contents 12...
Страница 156: ...Chapter 4 156...
Страница 202: ...Chapter 6 202...
Страница 244: ...Chapter 7 244...
Страница 292: ...Chapter 10 292...
Страница 330: ...Chapter 12 330...
Страница 356: ...Chapter 13 356...
Страница 372: ...Chapter 14 372...
Страница 442: ...Chapter 16 442...
Страница 472: ...Chapter 18 472...
Страница 520: ...Chapter 19 520...
Страница 536: ...Chapter 20 536...
Страница 562: ...Chapter 23 562...
Страница 566: ...Chapter 24 566...
Страница 602: ...Chapter 27 602...