User Guide
1006 Chapter 14: Properties
spriteNum
Usage
-- Lingo syntax
spriteObjRef.spriteNum
// JavaScript syntax
spriteObjRef.spriteNum;
Description
Sprite property; determines the channel number the behavior’s sprite is in and makes it available
to any behaviors. Read-only.
Simply declare the property at the top of the behavior, along with any other properties the
behavior may use.
If you use a
new() handler to create an instance of the behavior, the script’s new() handler must
explicitly set the
spriteNum property to the sprite’s number. This provides a way to identify the
sprite the script is attached to. The sprite’s number must be passed to the
new() handler as an
argument when the
new() handler is called.
Example
In this handler, the spriteNum property is automatically set for script instances that are created by
the system:
-- Lingo syntax
property spriteNum, pMySpriteRef
on mouseDown me
sprite(spriteNum).member = member("DownPict")
end
// JavaScript syntax
function mouseDown() {
sprite(this.spriteNum).member = member("DownPict");
}
This handler uses the automatic value inserted into the spriteNum property to assign the sprite
reference to a new property variable
pMySpriteRef, as a convenience:
-- Lingo syntax
property spriteNum, pMySpriteRef
on beginSprite me
pMySpriteRef = sprite(me.spriteNum)
end
// JavaScript syntax
function beginSprite() {
this.pMySpriteRef = sprite(this.spriteNum);
}