A reader asks:
On page 137 of Director in a Nutshell, you show that setting "property spriteNum" at the beginning of a behaviour will allow you to use "spriteNum" in place of "the spriteNum of me". Is this unique to the spriteNum property or can one do this with other properties?
The spriteNum is a unique property of me. It is automatically assigned a value when the Behavior is instantiated. However, you can simulate a similar thing with any property by declaring it as a property variable and setting an initial value for the custom property in the beginSprite handler. (The following example uses D7's dot syntax.) In almost all my Behaviors, I create a custom property pSpr that I then use throughout other handlers, such as:
property pSpr, pOrig, pHigh, spriteNum on beginSprite me pSpr = sprite(spriteNum) pOrig = pSpr.member pHigh = member(pSpr.memberNum + 1) end on mouseEnter me pSpr.member = pHigh end on mouseLeave me pSpr.member = pOrig end
Note that using pSpr is also faster than using sprite(spriteNum) repeatedly, because Director doesn't need to repeatedly create a sprite object. This is described in my article on dot syntax. Also note that you can NOT use pOrig in place of pSpr.member. to change the member of sprite. The following will simply set pOrig to the value of pHigh.
on mouseEnter me pOrig = pHigh end
In most cases, I only need spriteNum once in my Behavior, so in practice I rarely declare spriteNum as a property and instead use me.spriteNum (which is much shorter than the verbose the spriteNum of me in D6). I'll skip declaring property spriteNum and write the above beginSprite handler as:
property pSpr, pOrig, pHigh on beginSprite me -- Note, I use me.spriteNum instead of spriteNum pSpr = sprite(me.spriteNum) pOrig = pSpr.member pHigh = member(pSpr.memberNum + 1) end
Zeus Home Page | LIAN TOC | DIAN TOC | Links | E-Mail
Place an Order | Downloads | FAQ | GuestBook | Glossary
Copyright © 1996-1999 Bruce A. Epstein. All Rights Reserved.
(The page last revised November 4, 1999)