User Guide
Behaviors 369
Example of a complete behavior
If the handlers described here were in one behavior, the script would look like this (the
puppetSound command was added to the on mouseUp handler in this example):
property movement, noise
on getPropertyDescriptionList
set description = [:]
addProp description, #movement, [#default: 5, ¬
#format:#integer, #comment: "Set motion to ¬
the right:", #range: [#min:1, #max:10]]
addProp description, #noise, [#default:"", ¬
#format: #sound, #comment:"Sound cast ¬
member name"]
return description
end
on getBehaviorDescription
return "This changes sprite color and position"
end
on mouseUp me
set the foreColor of sprite the spriteNum of me ¬
to random(255)
puppetSound noise
end
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 + ¬
movement)
end if
end
When this behavior is attached to a sprite, each time the playhead enters a frame, the sprite moves
to the right by the amount the user specifies. When the user clicks a sprite, its color changes and a
specified sound plays.
Sending messages to behaviors attached to sprites
Lingo can run handlers in behaviors attached to specific sprites by sending messages to the
behaviors attached to one sprite, all sprites, or several specific sprites.
Sending messages to a sprite
The sendSprite command sends a message to a specified sprite. If none of the sprite’s behaviors
has a handler that corresponds to the message, the message passes to the cast member script, the
frame script, and then the movie script. See
sendSprite in the Lingo Dictionary.