You will often want to create widgets that can respond to user actions.
LiveCode Builder provides a range of messages, similar to LiveCode even messages, some examples are:
- OnMouseDown
- OnMouseUp
- OnDoubleClick
- OnKeyPress
You can choose which of these messages your widget will handle and how to handle them. Note that the event names are all one word, e.g. OnMouseUp, unlike LiveCode Script.
You can can also post messages to the widget object in LiveCode, these can be standard messages such as mouseUp or customised messages, such as segmentClicked in a Pie Chart widget.
Handling mouseUp
When the widget is clicked we want it to get a mouseUp message, just like a button or graphic control.
To do this we handle the LCB OnMouseUp message and post a mouseUp message to the widget object.
Add the OnMouseUp() handler to the widget code.
Note: Properties and events are, by their nature, always public as they define things which are external to the widget.
Testing mouseUp
Compile and test the widget using the Extension Builder.
- Go into Edit mode.
- Select the widget on the test stack.
- Open the Code editor for the widget and add a mouseUp handler
- Go into Run mode.
- Click the widget.
- The widget will respond to the mouse click.
Custom messages
You can post any message to the widget object, not just LiveCode messages.
For example if you want the Rotated Text Widget to receive a rotatedTextClicked message instead of a mouseUp message when it is clicked you would post “rotatedTextClicked”.