User Guide

Behaviors 365
New Action
executes any Lingo function or sends a message to a handler. You specify the new
handlers name.
Writing behaviors with Lingo
If you are familiar with Lingo, you can author your own behaviors.
From the perspective of Lingo, a behavior is a script with these additional features:
Each instance of the behavior has independent values for properties. Lingo uses a property
statement to declare properties that can have independent values in each instance of the
behavior. See
property in the Lingo Dictionary.
The same set of handlers can be shared by multiple sprites or frames.
The handlers in a behavior are basically the same as other handlers. Include as many handlers
as appropriate to implement the behavior.
A behavior is usually attached to multiple sprites or frames. As a result, the sprites and frames
share the same handlers. Director tracks which instance of the behavior is which by assigning
each instance a reference number. The variable
me contains the reference for the object that the
instance of the behavior is attached to.
In many cases its most efficient to create behaviors dedicated to specific tasks and then attach a
set of behaviors that perform the variety of actions you want.
The behavior can have parameters that users edit from the Parameters dialog box. The optional
on getPropertyDescriptionList handler sets up the Parameters dialog box. See on
getPropertyDescriptionList
in the Lingo Dictionary.
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. See
on getBehaviorDescription in the Lingo Dictionary.
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. See
on getBehaviorTooltip in the Lingo Dictionary.
Setting up a Parameters dialog box
It’s 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:
on enterFrame me
if the locH of sprite the spriteNum of me > the stageRight then
set the locH of sprite the spriteNum of me = the stageLeft
else
set the locH of sprite the spriteNum of me to ¬
(the locH of sprite the spriteNum of me + 5)
end if
end
However, users could adjust the speed of each sprite if they could specify how far individual
sprites move to the right in each frame.