Name

handler — Attaches an event handler to an object or class.

Synopsis

LZX: handler
Type: Class
Access: public
Topic: LZX.Basics

Description

Attaches a handler method for the named event to the object that contains this element.

The name attribute gives the event for which this handler should be invoked.

Events can be declared via the event tag. Events are also generated whenever the value of an attribute is changed using the setAttribute method.

For example, if a handler is defined via:

<view id="obj">
  <hander name="onkeydown" args="kc">
   if (kc == 13) this.doAction()
  </handler>
  <method name="doAction">
    Debug.write("action");
  </method>
</view>

then script code obj.onmyevent.sendEvent(259) will output "action".

The argument passed to an event handler is whatever value was used in the call to sendEvent() which generated the event. In the case where an attribute value is set using setAttribute, the new value is sent as the argument to sendEvent, and that will be the argument value received to any user-defined handler for that event.

If the @method attribute is given, a method body is unnecessary and the named method will be invoked instead. For example, the handler below has the same behavior as the earlier example.

<view id="obj">
  <hander name="onkeydown" method="doAction"/>
  <method name="doAction" args="kc">
   if (kc == 13)
     Debug.write("action");
  </method>
</view>

Superclass Chain

handler

Known Subclasses

Details

Initial Attributes (4)

Initial Attributes are given as attributes in LZX but are not generally available as properties in JavaScript.

args
<attribute name="args" type="string" value="""" />
The parameter names of this handler. The value of this attribute is a comma-separated list of JavaScript identifiers. Required if a method body is given as the handler implementation.
method
<attribute name="method" type="string" />
A method to call when this handler is invoked.
name
<attribute name="name" type="token" />
The name of the event.
reference
<attribute name="reference" value=""this"" />
If this attribute is present, it is a JavaScript expression that evaluates to an object. The code in this method executes when this object sends the event named by the @a{event} attribute. This attribute may be present only if the @a{event} attribute is present too.

LZX Synopsis

<class name="handler">
</class>