Chapter 16
422
Checking child object properties
You can check the values of specific property variables in individual child objects by using a
simple
objectName.PropertyName
syntax. For example, this statement assigns the variable
x
the
value of the
carSpeed
property of the child object in the variable
car1
:
x = car1.carSpeed
Querying object properties from outside the objects themselves can be useful for getting
information about groups of objects, such as the average speed of all the car objects in a racing
game. You might also use the properties of one object to help determine the behavior of other
objects that are dependent on it.
In addition to checking the properties 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.
These statements check whether the object
car1
was created from the parent script named Car:
if car1.script = script("Car") then
beep
end if
You can also get a list of the handlers in a child object by using the
handlers()
function, or
check whether a particular handler exists in a child object by using the
handler()
function.
This statement places a list of the handlers in the child object
car1
into the variable
myHandlerList
:
myHandlerList = car1.handlers()
The list would look something like this:
[#start, #accelerate, #stop]
These statements use the
handler()
function to check whether the handler
on accelerate
exists in the child object
car1
:
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. (The
actorList
property is useful for
tracking and manipulating the child objects in a movie. For details, see “Using actorList”
on page 423.)
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. For example, if
ball1
contains the only reference to a specific child object, then the
statement set ball1 = VOID
deletes the object from memory.
Содержание 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...