
Behaviors
365
New Action
executes any Lingo function or sends a message to a handler. You specify the new
handler’s 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 it’s 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.
Summary of Contents for Director MX
Page 1: ...Using Director MX Macromedia Director MX ...
Page 12: ...Contents 12 ...
Page 156: ...Chapter 4 156 ...
Page 202: ...Chapter 6 202 ...
Page 244: ...Chapter 7 244 ...
Page 292: ...Chapter 10 292 ...
Page 330: ...Chapter 12 330 ...
Page 356: ...Chapter 13 356 ...
Page 372: ...Chapter 14 372 ...
Page 442: ...Chapter 16 442 ...
Page 472: ...Chapter 18 472 ...
Page 520: ...Chapter 19 520 ...
Page 536: ...Chapter 20 536 ...
Page 562: ...Chapter 23 562 ...
Page 566: ...Chapter 24 566 ...
Page 602: ...Chapter 27 602 ...