Lingo Dictionary > G-K > on isOKToAttach |  |

on isOKToAttach

Syntax

    on isOKToAttach me, spriteType, spriteNum

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 will only be called during the initial attachment of the behavior to the sprite or script channel and will not be called again when any other changes are made to the sprite.

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:

    on isOKToAttach me, spriteType, spriteNum
    	case spriteType of
    		#graphic: -- any graphic sprite type
    			return sprite(spriteNum).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