Livecode Wiki
Advertisement

LiveCode is based upon events. Every action a script takes is triggered by an event, which is sent in the form of a message.

Messages are sent by events. Events include user actions (such as typing a key or clicking the mouse button) and program actions (such as completing a file download or quitting the application). LiveCode watches for events and sends a message to the appropriate object when an event occurs.

If you want your application to do something when a particular event occurs you handle the message that is sent by writing a message handler with the same name as the message.

Message path


The Message Path[]

The message path is the set of rules that determine which objects, in which order, have the opportunity to respond to a message. The message path is based on the object hierarchy.

Each LiveCode object is part of another object, of a different object type. For example, each card is part of a stack, each grouped control is part of a group, and so on. This object hierarchy defines the ownership and inheritance relationship between objects.

When a message is sent to an object, it is often handled directly by a message handler in that object. However if no handler is present, the message continues along a path until it finds a message handler that can respond to it. The object hierarchy is closely related to the path that a message travels on. In most cases, when an object passes a message on, the message goes to the object's owner in the object hierarchy.

The Path of a Message[]

For example, suppose the user clicks a button in a main stack, causing LiveCode to send a mouseUp message to the button. If the button's script does not contain a handler for the mouseUp message, the message is passed along to the card the button is on. If the card's script contains a mouseUp handler, the handler is executed. But if the card does not handle the mouseUp message, it is passed on to the card's stack. If the stack script contains a mouseUp handler, the handler is executed. But if the stack does not handle the mouseUp message, it is passed on to the engine.

The engine is the end of the message path, and if a message reaches it, the engine takes any default action (e.g. inserting a character into a field or highlighting a button), then throws the message away.

Try the following code on card, group and buttons:

on mouseUp
  answer the short name of the target 
end mouseUp

depending which object has or not it the result will be different.

Advertisement