Events underly most of the functionality in OpenLaszlo applications. Unlike events in similar systems, OpenLaszlo's events are point-to-point, meaning that there is no general broadcast mechanism for events, and events do not trickle up or down the instance hierarchy. Instead, objects called <handler>s use LzDelegate.register() to register to receive events.
An event is implicitly declared for every attribute of a class
or instance and sent when that attribute is changed. So, for
instance, if a class has an attribute
foo, you can
receive events when foo changes by registering for the
Events are sent with a single argument, which usually conveys
information about the property that changed. The default behavior
of the LzEventable.setAttribute() method is
to set the named property and send the event called "on" +
property. This is general mechanism that updates constraints in a
OpenLaszlo programs. For instance, when a view changes its
x position, it sends the event
onx with the new value for its
Example 14. Event sending in response to setting an attribute
this.setAttribute('avalue', this.avalue + 10)"
this.setAttribute('avalue', this.avalue + 5)"> <
// Handle the implicit `onavalue` event of the `eventSender` button<
this.setAttribute('x' , v);</
An event can be explicitly declared using the
<event> tag and the
method is used to explicitly send an event.
Example 15. A simple example of publishing and listening for a custom event
Debug.debug("event: %s", event); this.setAttribute('x', this.x + 10);</
Sending an event that no delegate is listening for has nearly no cost, thus objects can freely publish events.
See the Developer's Guide for more detailed information on using events and delegates.
|eventValue||*||(Optional) The value to pass when executing
the delegates registered to receive the event. If omitted,
Copyright © 2002-2010 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.