Creating the on new handler
Each parent script typically uses an
when another script issues a
specified parent script to create a child object from itself. The
can also set the child object's initial property values, if you want. The
with the phrase
on new
child object. See
new()
The following is a sample
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
This handler creates a new child object from the parent script and initializes the child's
property with the value passed to it in the
spriteNum
statement returns the child object to the handler that originally called the
more information about calling the
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 the code above to make
the sprite change color.
The following parent script defines a value for the property
handler that will change the
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
on changeColor me
spriteNum.forecolor = random(255)
end
Using the me variable
Typically, one parent script creates many child objects, and each child object contains more than
one handler. The term
variable stated in every handler definition in a parent script.
The
variable tells the handlers in the child object that they are to operate on the properties of
me
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 will use its own child object's values for those
properties.
This is why it is always important to define
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.
420
Chapter 16
handler. This handler creates the new child object
on new
new(script parentScriptName)
, followed by the
variable and any arguments being passed to the new
me
in the Lingo Dictionary.
handler:
on new
handler, see "Creating a child object" on page 421.
on new
property of the sprite.
forecolor
is a special parameter variable. It must always be the first parameter
me
me
command, which tells the
on new
on new
argument. The
aSpriteNum
spriteNum
as the first parameter for parent scripts and to pass
handler in the parent script
handler always starts
return me
handler. For
on new
and contains a second
Need help?
Do you have a question about the DIRECTOR MX-USING DIRECTOR MX and is the answer not in the manual?
Questions and answers