Events Defined in the LzNode and LzView Classes

Since all OpenLaszlo classes are directly or indirectly derived from the LzNode class and all views and components are subclasses of LzView, the events defined in these two classes are inherited by the majority of objects ever created in LZX applications and therefore are worth discussing.

Event names in OpenLaszlo start with on followed by an action. For example, the event caused by the user click is onclick. The event raised when the mouse button is released is onmouseup.

The following are the events defined in the LzNode class.

onconstruct

This event is raised at the beginning of the instantiation process of this node.

ondata

This event is raised when the data referenced by this node’s datapath changes.

oninit

This event is raised right before a node becomes active.

Of the three, the oninit event is used most often. You use this event to write initialization code that needs to be executed when an object is initialized.

For example, Listing 5.1 shows an LZX application that employs the oninit event of the Alert class to invoke the open method on an Alert object.

Listing 5.1. Using oninit on an Alert window
<canvas>
    <alert name="warning" button1="Yes" button2="No">
        Do you want to continue?
        <handler name="oninit">
					this.open();
					</handler>
    </alert>
</canvas>

You can test the code by using this URL:

http://localhost:8080/lps-4.0.x/app05/oninitTest1.lzx

Figure 5.1 shows the generated result.

Figure 5.1. Using oninit on an Alert window


Without the event handler, the Alert window will not be displayed.

The LzView class has dozens of events, listed in Table 5.2.

Table 5.2. The events defined in LzView
EventDescription
onaddsubresourceRaised when a subview adds a resource.
onaddsubviewRaised when this view adds a subview.
onblurRaised when a focusable view loses focus.
onclickRaised when a clickable view is clicked.
ondblclickIf there is an event handler for this event, raised when a clickable view is double-clicked. If no event handler is registered, two consecutive onclick events will be sent instead.
onerrorRaised when there is an error when loading the view’s associated resource. The event will send the error message to the event handler.
onfocusRaised when a focusable view receives focus.
onheightRaised upon the view’s height change.
onlastframeRaised when the view sets its frame to the last frame. This event can be used to send a notification when the view finishes playing its associated resource.
onloadRaised when the view loads its associated resource.
onmousedownRaised when the mouse button is pressed on a clickable view.
onmousedraginRaised when the mouse is clicked and its pointer is dragged into a clickable view.
onmousedragoutRaised when the mouse is clicked on a clickable view and dragged out.
onmouseoutRaised when the mouse pointer moves out of a clickable view.
onmouseoverRaised when the mouse rolls over a clickable view.
onmouseupRaised when the mouse button is released on a clickable view.
onmouseupoutsideRaised when the mouse button that has been clicked upon a clickable view is released outside the view.
onopacityRaised when the opacity of a view changes
onplayRaised when a view begin playing its associated resource
onremovesubviewRaised when a subview is removed.
onstopRaised when the associated resource stops playing.
ontimeoutRaised when the request to load media for the view times out.
onwidthRaised when the width of a view changes.
onxRaised when the view’s x attribute changes.
onxscaleRaised when a view which is resizing in the x axis changes its width.
onyRaised when the view’s y attribute changes.
onyscaleRaised when a view which is resizing in the y axis changes its height.

As you can see, many of the LzView class’s events are raised when the value of an attribute changes. For example, the onwidth event is raised when the view’s width changes.

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

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