Well, as you can see Bill, there are many ways of interpreting things in Rev.
The message path is the most important concept to understand in this context.
In its simplest form, you want to have a way of reusing code so that you don't have to rewrite scripts for multiple objects in multiple stacks, right?
So, starting off simply (and forgive me for any uber-basic patronisation, which is not the intention), you have, say a couple of buttons on a card.
In button1 you have a mouseUp handler
Code: Select all
on mouseUp
answer "This is button 1"
end mouseUp
and button2 has a separate, specific nouseUp handler of its own
Code: Select all
on mouseUp
answer "This is button 2"
end mouseUp
If you use a common handler for each mouseUp event on each button you could put the same script in each button
Code: Select all
on mouseUp
doAnswer (the short name of me)
end mouseUp
and in the card script you can have a handler that each button will be able to reach
Code: Select all
on doAnswer pName
answer "This is button" && the last char of pName
--assuming single digit button naming applies - not a real world example!
end doAnswer
Putting the doAnswer script in the card makes it available to all the objects on that card. If you put it higher up the message path, in the stack script, you can make it available to all the objects in the stack.
Now you can also leave out the mouseUp handlers on each button on the card and put the mouseUp handler in the card or stack script. This means that on clicking (say) button1 (or any object in the card or stack accordingly), because you left out a specific mouseUp handler in "the target", the mouseUp message is not trapped by the "target" button and the mouseUp message will continue to follow the message path until it reaches a handler - which in this case you will have put in the card or stack script. By testing the (long) name of the target to check for appropriate conditions, the mouseUp message can be trapped and trigger the right actions accordingly. (This is what bernd was explaining with his examples.)
If you have multiple substacks and you leave out all mouseUp handlers and just have one mouseUp handler in the mainstack script, then clicking on objects in all the substacks will generate mouseUp messages which will travel along the message path until they reach the mainstack mouseUp handler. You can, if you wish, rely on just one mainstack mouseUp handler to respond to all the mouseUp (or any other) messages, but it would need to be quite sophisticated to work out what to do in the case of all the objects which may have created the message. Of course, it needn't have to handle "every" mouseUp message, because say you have a specific set of buttons on one card of one substack that would trigger different events and you don't want to have to test for every target permutation in the mainstack handler - just adding a mouseUp handler lower down the message path, on the card of the substack, or in the buttons themselves will intercept the mouseUp message and react, before the message gets to the mainstack. Unless you "pass" the message in the more local script, it will be trapped there and not trigger any events via the mainstack handler.
If you want to reuse code on multiple projects, then creating a library stack, or making front/back scripts are useful options. A library stack is somewhat less ingrained and potentially simpler and/or more flexible, depending on your needs. If you "start using <librarystackname>" (usually somewhere like in the openStack handler of your project mainstack) then you can make the library handlers available to the mainstack and all its substacks. So by creating a generic mouseUp handler and putting it into a library stack, then telling the project mainstack to "start using" the library, you can click a button on a card of a substack and that will generate a mouseUp message, which will (ignoring front scripts for now) travel from the button, through any group script of which it may be a member, the card script, any background group script of which it may be a member, the substack script, the mainstack script, then the library, any backscripts, and finally the engine. If the mouseUp message reaches a mouseUp handler at any point along the path then the handler will kick in, and the mouseUp message will stop at that point, unless the handler specifically "passes" the message.
Does that make it any clearer?