60
Chapter 3: Writing Scripts in Director
In addition to checking the properties that you assign, you can check whether a child object
contains a specific handler or find out which parent script an object came from. This is useful
when you have objects that come from parent scripts that are similar but that have subtle
differences.
For example, you may want to create a scenario in which one of several parent scripts might be
used to create a child object. You can then determine which parent script a particular child object
came from by using the
script()
function, which returns the name of an object’s parent script.
The following statements check whether the object
car1
was created from the parent script
named
Car
:
-- Lingo syntax
if car1.script = script("Car") then
_sound.beep()
end if
You can also get a list of the handlers in a child object by using the
handlers()
method, or check
whether a particular handler exists in a child object by using the
handler()
method.
The following statement places a list of the handlers in the child object
car1
into the variable
myHandlerList
:
-- Lingo syntax
myHandlerList = car1.handlers()
The resulting list would look something like this:
[#start, #accelerate, #stop]
The following statements use the
handler()
method to check whether the handler
on
accelerate
exists in the child object
car1
:
-- Lingo syntax
if car1.handler(#accelerate) then
put("The child object car1 contains the handler named on accelerate.")
end if
Removing a child object
You can remove a child object from a movie by setting all variables that contain a reference to the
child object to another value. If the child object has been assigned to a list, such as
actorList
,
you must also remove the child object from the list.
To remove a child object and the variables that refer to it:
•
Set each variable to
VOID
.
Director deletes the child object when there are no more references to it. In the following
example,
ball1
contains the only reference to a specific child object, and it is set to
VOID
to delete
the object from memory.
-- Lingo syntax
ball1 = VOID
To remove an object from actorList:
•
Use the
delete()
method to delete the item from the list.
Summary of Contents for DIRECTOR MX 2004
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...