![MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference Download Page 57](http://html1.mh-extra.com/html/macromedia/director-mx-2004-director-scripting/director-mx-2004-director-scripting_reference_3321720057.webp)
Object-oriented programming with Lingo
57
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:
-- Lingo syntax
ancestor = new(script "What_Everyone_Does")
When handlers and properties are not defined in a child object, Director searches for the handler
or property in the child’s ancestors, starting with the child’s parent script. If a handler is called or
a property is tested and the parent script contains no definition for it, Director searches for a
definition in the ancestor script. If a definition exists in the ancestor script, that definition is used.
A child object can have only one ancestor at a time, but that ancestor script can have its own
ancestor, which can also have an ancestor, and so on. This lets you create a series of parent scripts
whose handlers are available to a child object.
Writing a parent script
A parent script contains the code needed to create child objects and define their possible actions
and properties. First, you must decide how you want the child objects to behave. Then, you can
write a parent script that does the following:
•
Optionally declares any appropriate property variables; these variables represent properties for
which each child object can contain a value independent of other child objects.
•
Sets up the initial values of the child objects’ properties and variables in the
on new
handler.
•
Contains additional handlers that control the child objects’ actions.
Declaring property variables
Each child object created from the same parent script initially contains the same values for its
property variables. A property variable’s value belongs only to the child object it’s associated with.
Each property variable and its value persists as long as the child object exists. The initial value for
the property variable is typically set in the
on new
handler; if it’s not set, the initial value is
VOID
.
To declare a property variable:
•
Use the
property
keyword at the beginning of the parent script.
To set and test property variables from outside the child object:
•
Set and test property variables in the same way you would any other property in your scripts,
by using the syntax
objectRef.propertyName
.
For example, the following statement sets the
speed
property of an object
car1
:
car1.speed = 55
Creating the new handler
Each parent script typically uses an
on new
handler. This handler creates the new child object
when another script issues a
new(script
parentScriptName
)
command, which tells the
specified parent script to create a child object from itself. The
on new
handler in the parent script
can also set the child object’s initial property values, if you want.
The
on new
handler always starts with the phrase
on new,
followed by the
me
variable and any
parameters being passed to the new child object.
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...