User Guide
Sending messages to behaviors attached to sprites 287
Sending messages to behaviors attached to sprites
Script 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 method 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. For more information about this method, see the Scripting
Reference topics in the Director Help Panel.
For example, this handler sends the custom message
bumpCounter and the argument 2 to sprite 1
when the user clicks the mouse:
--Lingo syntax
on mouseDown me
sendSprite (1, #bumpCounter, 2)
end
// JavaScript syntax
function mouseDown() {
_movie.sendSprite(1, symbol("bumpCounter"), 2);
}
Note: The symbol (
#) operator must precede the message in the sendSprite method.
Sending messages to all sprites
The
sendAllSprites method sends a message to every sprite in the frame. If no behavior has a
handler that corresponds to the message, the message passes to the cast member script, the frame
script, and then the movie script. For more information about this method, see the Scripting
Reference topics in the Director Help Panel.
For example, this handler sends the custom message
bumpCounter and the argument 2 to all
sprites in the frame when the user clicks the mouse button:
--Lingo syntax
on mouseDown me
sendAllSprites (#bumpCounter, 2)
end
// JavaScript syntax
function mouseDown() {
_movie.sendAllSprites(symbol("bumpCounter"), 2);
}
Note: The symbol (
#) operator must precede the message in the sendAllSprites method.