Alloy supports MVC pattern architecture where we can have view, model and controllers by which we can separate UI block and program logic. So here we will see how can we add clock event to an UI element.
In order to add click event to an UI element, lets add an label index.xml that will resides in view section and we will add the click event function to the controller section.
So here we have define and window tag and assign a label tag to it. On label tag we have assign an id which will be unique ideally, and added an onClick event. The function associated click evevent need to be defined on controller associated with this view.
// Code to open index view
alert("Dont click me!");
On above code you can see that we have called index.open function to display the index view.
And also defined the function which will be called on click of the view element associated with this controller.
Summary : So here on view section we have define the UI element and and also assign the onclick event of that element but the function related with that event is defined in associated controller. So now on click of that label an alert message will shown displaying the message “Dont click me!”