behavior | |||||||
Type | property | ||||||
Dictionary | LCS | ||||||
Library | LiveCode Script | ||||||
Syntax |
| ||||||
Synonyms | parentscript | ||||||
Associations | stack, card, field, button, graphic, scrollbar, player, image, widget | ||||||
Summary | Allows an object to inherit its script handlers from another object. | ||||||
Introduced | 3.5 | ||||||
Changes | From version 6.7.5, a stack can be used as a behavior. From version 6.1, the behavior property of a control currently being used as a behavior will now be taken into account and result in the child behavior deferring to the parent behavior in the same way a control defers to its behavior. | ||||||
OS | mac, windows, linux, ios, android, web | ||||||
Platforms | desktop, server, mobile | ||||||
Example |
| ||||||
Values |
| ||||||
Related | Keyword: me Constant: empty Property: ID, name, password, stackFiles Command: dispatch Object: button, field, stack Glossary: object, control, file path, handler, message path, object reference, script, script local variable, stack file, substack | ||||||
Description | Behaviors are a method to create common functionality between objects without duplicating the scripts. The value of the behavior property is a reference to a button or stack containing the script to use. The format stored in the object it's assigned to is similar to a long ID. The main difference is that where a long ID includes the full path to the stack file, the form stored in the behavior includes only the stack name, allowing the reference to continue to work after the stack file has been moved to another computer. If you set the behavior to a long ID, LiveCode converts it to a rugged form without the stack file path. By default, the behavior of newly created objects is empty. An object with a behavior set will act as though its script was set
to the script of the behavior button or stack. If multiple
objects share the same behavior, each will have its own set of
script local variables. Any references to
The button or stack containing the behavior script can be located anywhere. In particular this allows for it be located in a password protected stack, allowing you to protect the script without need to protect the controls using it. Behaviors are resolved by LiveCode immediately after loading a stack file. The engine acts as though it is resolving a control reference of the form: button id id of stack stack name [ of stack mainstack name ] Thus the stackFiles property will be searched and stacks loaded into memory as appropriate. The behavior property does not track changes to the name of the stack and/or substack - if the name of a stack containing behavior objects is changed, then all references to these behaviors will be broken. This apparent strictness is necessary to ensure that behaviors act consistently while LiveCode is running. For example, let's say you have the following setup:
Then the message path will be:
Note: The synonym | ||||||
Tags | messages |