User Guide

632 Chapter 14: Properties
For child objects, the ancestor property is usually assigned in the on new handler within the
parent script. Sending a message to a child object that does not have a defined handler forwards
that message to the script defined by the
ancestor property.
If a behavior has an ancestor, the ancestor receives mouse events such as
mouseDown and
mouseWithin.
The
ancestor property lets you change behaviors and properties for a large group of objects with
a single command.
The ancestor script can contain independent property variables that can be obtained by child
objects. To refer to property variables within the ancestor script, you must use this syntax:
me.propertyVariable = value
For example, this statement changes the property variable legCount within an ancestor script
to 4:
me.legCount = 4
Use the syntax the variableName of scriptName to access property variables that are not
contained within the current object. This statement allows the variable
myLegCount within the
child object to access the property variable
legCount within the ancestor script:
set myLegCount to the legCount of me
Example
Each of the following scripts is a cast member. The ancestor script Animal and the parent scripts
Dog and Man interact with one another to define objects.
The first script, Dog, sets the property variable
breed to Mutt, sets the ancestor of Dog to the
Animal script, and sets the
legCount variable that is stored in the ancestor script to 4:
property breed, ancestor
on new me
set breed = "Mutt"
set the ancestor of me to new(script "Animal")
set the legCount of me to 4
return me
end
The second script, Man, sets the property variable race to Caucasian, sets the ancestor of Man
to the Animal script, and sets the
legCount variable that is stored in the ancestor script to 2:
property race, ancestor
on new me
set race to "Caucasian"
set the ancestor of me to new(script "Animal")
set the legCount of me to 2
return me
end
See also
new(), me, property