-- Lingo syntaxspriteObjRef.spriteNum // JavaScript syntaxspriteObjRef.spriteNum;
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.
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);
}
This approach allows the use of the reference pMySpriteRef later in the script, with the handler using the syntax:
-- Lingo syntax currMember = pMySpriteRef.member // JavaScript syntax var currMember = pMySpriteRef.member
instead of the following syntax which is somewhat longer:
-- Lingo syntax currMember = sprite(spriteNum).member // JavaScript syntax var currMember = sprite(this.spriteNum).member
This alternative approach is merely for convenience, and provides no different functionality.