spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column23


Behavior Handler's Event Element

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


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

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