Spot on - now I understand
Cheers
On Friday, June 22, 2001, at 05:30 PM, Irv Kalb wrote:
> OK, I'll have to I'll have to correct you. In the original posting,
> the question was about having two behaviors attached to the same sprite
> and how to send a message from one behavior to the other behavior.
>
> If you do what I suggest, by using "spriteNum" instead of hard-coding
> the number, the property variable "spriteNum" will automatically be
> given the proper value, in this case 3. "spriteNum" does not get a
> reference to the sprite (as in sprite(3)), it gets the actual value 3.
> So the sendSprite call broadcasts a message to _all_ behaviors attached
> to sprite 3. The receiver of this message is in a different behavior.
>
> So here's an example. Let's say you have two behaviors A and B that
> are both attached to sprite 3:
>
> -- Behavior A
> property spriteNum
>
> on mouseUp me
> sendSprite(spriteNum, #someSpecialHandlerName, someValue)
> end
>
>
> -- Behavior B
> on someSpecialHandlerName me, someParameter -- don't forget the "me"
> -- do some code here
> end
>
>
> The question is why would you want to do such a thing? And the answer
> is for re-use of behaviors. This is my standard way of handling
> buttons. I use a generic button script on all my buttons, and when
> that behavior determines that the button has been clicked on, it does a:
>
> sendSprite(spriteNum, #mHit)
>
> I also attach a second behavior to all my buttons to carry out the
> action of the button in an "mHit" handler. For example, let's say I
> have a Previous and a Next button. On both buttons I add my generic
> button behavior that handles rollovers, and down and up and gray
> states. Then on the Previous button I add a behavior that has an mHit
> handler that does the proper code for whatever I do when Previous is
> hit. And on the Next button, I add a behavior that has an "on mHit"
> handler that does what I want to do when the Next button is hit. For
> more details on this, see my article on DOUG at:
>
> http://www.director-online.com/accessArticle2.cfm?id=340
>
> Irv
>
>
> At 4:35 PM +0100 6/22/01, Pete Carss wrote:
>> Correct me if I'm wrong - I mean this - CORRECT me if I'm wrong - but
>> in the case below wouldn't "spriteNum" hold a reference to the sprite
>> that the behaviour was attached to - and in effect, the behaviour
>> would be sending the message to itself?
>>
>> Pete
>>
>> On Friday, June 22, 2001, at 03:57 PM, Irv Kalb wrote:
>>
>>> Others have already pointed out the need for the "me" variable. But
>>> I'll add something else. If you have a behavior where to want to
>>> send something to the same sprite number, instead of hard coding the
>>> sprite number, use the built in "spriteNum" variable. For example,
>>> instead of:
>>>
>>> sendSprite(3, #checkRight, 15)
>>>
>>> use
>>>
>>> sendSprite(spriteNum, #checkRight, 15)
>>>
>>> And be sure to declare "property spriteNum" as the top of the script.
>>> This makes the behavior much more general. You could use it in any
>>> channel, and it will continue to work if you move your sprite from
>>> channel 3 to some other channel.
>>>
>>> Irv
>
>
>
> --
> Lingo / Director / Shockwave development for all occasions.
> (Home-made Lingo cooked up fresh every day just for you.)
>
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
> email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming Lingo. Thanks!]
>
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]