User Guide
178 Chapter 10: Events and Messages
on isOKToAttach
Usage
-- Lingo syntax
on isOKToAttach me, aSpriteType, aSpriteNum
statement(s)
end
// JavaScript syntax
function isOKToAttach(aSpriteType, aSpriteNum) {
statement(s)
}
Description
Built-in handler; you can add this handler to a behavior in order to check the type of sprite the
behavior is being attached to and prevent the behavior from being attached to inappropriate
sprite types.
When the behavior is attached to a sprite, the handler executes and Director passes to it the type
of the sprite and its sprite number. The
me argument contains a reference to the behavior that is
being attached to the sprite.
This handler runs before the
on getPropertyDescriptionList handler.
The Lingo author can check for two types of sprites.
#graphic includes all graphic cast members,
such as shapes, bitmaps, digital video, text, and so on.
#script indicates the behavior was
attached to the script channel. In this case, the
spriteNum is 1.
For each of these sprite types, the handler must return
TRUE or FALSE. A value of TRUE indicates
that the behavior can be attached to the sprite. A value of
FALSE prevents the behavior from being
attached to the sprite.
If the behavior contains no
on isOKToAttach handler, then the behavior can be attached to any
sprite or frame.
This handler is called during the initial attachment of the behavior to the sprite or script channel
and also when attaching a new behavior to a sprite using the Behavior inspector.
Example
This statement checks the sprite type the behavior is being attached to and returns TRUE for any
graphic sprite except a shape and
FALSE for the script channel:
-- Lingo syntax
on isOKToAttach me, aSpriteType, aSpriteNum
case aSpriteType of
#graphic: -- any graphic sprite type
return sprite(aSpriteNum).member.type <> #shape
-- works for everything but shape cast members
#script: --the frame script channel
return FALSE -- doesn't work as a frame script
end case
end