Internet Explorer 5.0, Part II: Behavior Handler's Event Element- Doc JavaScript | WebReference

Internet Explorer 5.0, Part II: Behavior Handler's Event Element- Doc JavaScript


Behavior Handler's Event Element

Behaviors expose their custom events via the event element. The syntax of the event element is as follows:

<EVENT NAME="eventName"/>
Because the event element contains no child elements, the syntax above is equivalent to:

<EVENT NAME="eventName"></ELEMENT>
The event element is a child of the scriptlet's Behavior-type Imlements element. In our Connect Three example, we define two events. The onBoxLoad event is fired nine times, once for every box loaded in the game board. The onBoxClick event is fired whenever a player clicks an empty box. Here is the Connect Three example's Behavior-type Imlements element:

<IMPLEMENTS ID="kuku" TYPE="Behavior" DEFAULT>
<EVENT NAME="onBoxLoad"/>
<EVENT NAME="onBoxClick"/>
</IMPLEMENTS>

Let's see now how the calling page acts upon these events. In the Connect Three example, every box is a separate image to which the above two events are applied. Here is the top left box definition:

<IMG CLASS="tripleBox" x="50" y="50" onBoxClick="handleBoxClick()"
onBoxLoad="handleBoxLoad(1,1)">

We can see that handlers for custom events are defined exactly as those for default intrinsic events, such as the onclick event. Notice that whenever a custom event name is identical to an intrinsic one, the default behavior of that particular element is overridden by the behavior defined in the Behavior scriptlet. If the default behavior of a radio button, for example, is to appear selected after an onclick event, a behavior scriptlet can override the button's behavior by specifying a different event handler.

For the event to be communicated to the containing page, the custom event needs to be fired in the scriptlet. In our example, the onLoadBox event is fired simply when a box is loaded:

fireEvent("onBoxLoad",loadEvent);

Similarly, the onLoadBox event is fired after a click event has been processed successfully:

fireEvent("onBoxClick",clickEvent);

The meaning of the fireEvent's second parameter is explained later in this column, under the fireEvent page.

http://www.internet.com


Created: August 11, 1998
Revised: August 11, 1998

URL: http://www.webreference.com/js/column23/event.html