58
Chapter 3: Writing Scripts in Director
The following
on new
handler creates a new child object from the parent script and initializes the
child’s
spriteNum
property with the value passed to it in the
aSpriteNum
parameter. The
return
me
statement returns the child object to the handler that originally called the
on new
handler.
-- Lingo syntax
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
For more information on calling the
on new
handlers, see
“Creating a child object” on page 59
.
Adding other handlers
You determine a child object’s behavior by including in the parent script the handlers that
produce the desired behavior. For example, you could add a handler to make a sprite
change color.
The following parent script defines a value for the property
spriteNum
, and contains a second
handler that changes the
foreColor
property of the sprite.
-- Lingo syntax
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
on changeColor me
spriteNum.foreColor = random(255)
end
Referring to the current object
Typically, one parent script creates many child objects, and each child object contains more than
one handler. The special parameter variable
me
tell the handlers in a child object that they are to
operate on the properties of that object and not on the properties of any other child object. This
way, when a handler within a child object refers to properties, the handler uses its own child
object’s values for those properties.
The term
me
must always be the first parameter variable stated in every handler definition in a
parent script. It is always important to define
me
as the first parameter for parent scripts and to
pass the same parameter if you need to call other handlers in the same parent script, since these
will be the handlers in each of the script’s child objects.
When referring to properties defined in ancestor scripts, you must use the
me
parameter as the
source of the reference. This is because the property, while defined in the ancestor script, is
nevertheless a property of the child object. For example, the following statement uses
me
to refer
to an object and access properties defined in an ancestor of the object:
-- Lingo syntax
x = me.y -- access ancestor property y
Because the variable
me
is present in each handler of a child object, it indicates that all the
handlers control that same 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...