Livecode Wiki

A Message sent to the destination card right after you open a stack. If there is a message handler by the same name in the message path, then it will be executed.




The openStack message is sent after the stack is visible.

Message handler[]


on openStack
  send "rollCredits" to field "Credits"
end openStack

Use the openStack Message handler to change a stack's objects, or perform other updates, when the stack is opened.

The OpenStack message is sent to the current card, but if it isn't the card, it's sent to the stack. So if you put a Openstack Message handler both in stack and in card, only the one in the card will be executed.

To make changes that take effect before the stack becomes visible on the screen, use a preOpenStack handler instead of openStack.

If you put the OpenStack message handler in the mainstack, all substacks will activate it, so this could can prevent to activate the handler in substacks:

on OpenStack
 if the owner of the target is me then
                     -- code runs for this stack only
    answer "Opened mainstack"
                     -- code runs for any stack that's opened other than this one
    answer "Opened a Substack"
 end if
end OpenStack

The actual opening is not triggered by the openStack message, so trapping the message and not allowing it to pass does not prevent the stack from opening.

See also: openBackground, resume & stack.