User Guide

288 Chapter 12: Behaviors
Sending messages to specific behaviors only
The
call method sends an event to specific behaviors. Unlike the sendSprite method, the call
method does not pass the message to frame scripts, scripts of the cast member, or movie scripts.
Before sending a message to a specific behavior, check the
scriptInstanceList sprite property
to find a behavior script reference to use with the
call method.
The
scriptInstanceList property provides a list of references for the behaviors attached to a
sprite while a movie is playing.
For example, this handler displays the list of references for all behaviors attached to the same
sprite as this behavior’s handler:
--Lingo syntax
on showScriptRefs me
put sprite(me.spriteNum).scriptInstanceList
end
// JavaScript syntax
function showScriptRefs() {
trace(sprite(spriteNum).scriptInstanceList);
}
This handler sends the message bumpCounter to the first script reference attached to sprite 1 (the
getAt method identifies the first script reference in the scriptInstanceList):
--Lingo syntax
on mouseDown me
xref = getAt(sprite(1).scriptInstanceList, 1)
call (#bumpCounter, xref, 2)
end
// JavaScript syntax
function mouseDown() {
xref = sprite(1).scriptInstanceList.getAt(1);
bumpCounter (xref, 2);
}
Note: The symbol (
#) operator must precede the message in the call method.
To remove all instances of a sprite while the movie is playing:
Set the sprites scriptInstanceList property to an empty list([]). For more information
about this property, see the Scripting Reference topics in the Director Help Panel.