spacer

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

home / experts / javascript / column23


Behavior Handler's Event Element

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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