>>> I always had the (wrong!) impression that every openStack handler is
>>> only called once, and also that it belongs to the stack containing it.

Others have described the hierarchy, but I thought I'd offer some clarification 
related to why some people have suggested to put the openStack trap of your 
main stack in the first card of the stack instead of the stack script, and to 
offer an alternative:

If you put an openStack handler in the stack script of your mainstack, and just 
open the mainstack, the "openStack" message passes through the hierarchy like 
this:

openStack
    -> script of first card of mainstack
    -> stack script of mainstack
    -> backscripts/libraries/etc.

If you open a *substack* of the mainstack, the openStack message passes through 
the hierarchy like this:

openStack
    -> script of first card of substack
    -> stack script of substack
    -> stack script of mainstack
    -> backscripts/libraries/etc.

Notice that the message does NOT go to the first card of the mainstack! So if 
you move your openStack handler of your mainstack from the stack script to the 
first card of the mainstack, it will still be triggered when the *mainstack* 
opens, but it will NOT be triggered when a *substack* opens.

Coming from HyperCard/SuperCard development, and in my early years of working 
with MetaCard/Revolution, it seemed "weird" to me that I would have 
stack-related handlers in a card script. So to keep the handler in the 
mainstack script but *not* have it trigger when a substack opened, I had my 
mainstack's openStack handler look like this:

on openStack
  if the owner of the target is me then
    -- do mainstack-only stuff
  else
    -- either do nothing, or do substack-only stuff
  end if
end openStack

Since the openStack message hits the card first, the "owner of the target" is 
the mainstack (or substack) itself… so by testing "if the owner of the target 
is me" inside the mainstack's stack script, I could isolate openStack messages 
from the mainstack opening vs. any of its substacks.

Hope this helps clarify things,

Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Web Site: http://www.sonsothunder.com/  

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to