User Guide
282 Chapter 12: Behaviors
• The behavior can have parameters that users edit from the Parameters dialog box. The optional
on getPropertyDescriptionList handler sets up the Parameters dialog box. For more
information, see the Scripting Reference topics in the Director Help Panel.
• A description of the behavior can be added to the Behavior inspector. The optional on
getBehaviorDescription
handler displays a description of the behavior in the Behavior
inspector. For more information, see the Scripting Reference topics in the Director Help Panel.
• A brief description appears as a tooltip for the behavior in the Library palette if the optional on
getBehaviorToolTip
handler that creates the tooltip has been written. For more
information, see the Scripting Reference topics in the Director Help Panel.
Setting up a Parameters dialog box
It is impossible to predict exactly what a user will want behaviors to do. You can make behaviors
more flexible by letting the user customize the behavior’s parameters.
For example, this handler moves the sprite 5 pixels to the right each time the playhead enters a
new frame:
if ( sprite(me.spriteNum).locH > window("stage").rect.right ) then
sprite(me.spriteNum).locH = window("stage").rect.left
else
sprite(me.spriteNum).locH = sprite(me.spriteNum).locH + 5
end if
However, users could adjust the speed of each sprite if they could specify how far individual
sprites move to the right in each frame.
To allow users to set different values for a property in different instances of the behavior, the
behavior’s script needs the following:
• A property statement (Lingo) or a var statement (JavaScript syntax) that allows each instance
to maintain a separate value for the property
• An on getPropertyDescriptionList handler that sets up the property or variable.
Setting behavior properties with script
Behaviors usually have properties for which each instance of the behavior maintains its own
values. (An instance is the unique instance of the behavior assigned to sprites or frames.) These
properties are shared among handlers in a behavior’s script the same way that properties are shared
among handlers in an object.
To declare properties in each instance of the behavior:
• Put the property or var statement at the beginning of the behavior’s script.
A
property or var statement starts with the word property or var followed by the names of the
individual properties or variables. For example, the statement property movement declares that
movement is a property of the behavior.