Chapter 5. Event Handling

OpenLaszlo objects can raise events. Some events are raised as the response to the user’s action, such as a mouse click or a keyboard input. Some are raised programmatically, for example as the response to data change. You can harness this feature to make your applications more interactive. If you have programmed JavaScript, you’ll feel very much at home with OpenLaszlo event programming. All you need to do to respond to an event is write an event handler and link the handler to the event in question.

How do you write an event handler? In Chapter 1, “Starting OpenLaszlo” you’ve seen that you can use the script tag to write a JavaScript script that will be executed when the application loads. Event handlers are basically methods or functions. Therefore, you can write JavaScript functions within a script tag. However, since scripts can only appear directly within <canvas>, you use the script tag for global functions that will be called from multiple points in an application. If your function is local to an object, you should write a method under the tag that creates the object that raises the event.

This chapter shows you how to deal with events and event handlers. Most events are defined in the LzNode and LzView classes. Therefore, a list of events in these two classes will be given first.

Note

If you are not familiar with JavaScript, make sure you read Appendix B, “Introduction to JavaScript” before you read this chapter.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset