spacer

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

home / experts / javascript / column22


Passing Events from a Behavior

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

We have covered in previous pages how to pass objects and data to a Behavior. But a Behavior not only accepts data -- it also generates events according to your specifications. In our Blinking Soccer Ball example, we define an event called onFifthBlink, which signals the fifth blink of the soccer image. Behavior's events are defined in the scriptlet's interface section, in the Behavior type of IMPLEMENTS tags:

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

The generation of the event inside the scriptlet's implementation section is accomplished via the fireEvent() method. In our example, we simply count the number of blinks and then invoke the fireEvent() function after five blinks:

  counter +=1;  
if (counter == 10) {
fireEvent("onFifthBlink");
counter = 0;
}

Notice that we count to 10 instead of 5, because each blink consists of two visibility changes. Also, we reset the counter variable, to allow the event to be fired after every five blinks, not necessarily the first five.

The fired events are associated with the DHTML element from which the Behavior was called. In our Blinking Soccer example, we just pop up an alert box every five blinks:

<DIV CLASS="soccer" ... onFifthBlink = "alert('Fifth Blink Point')" ...

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: July 19, 1998
Revised: July 19, 1998

URL: http://www.webreference.com/js/column22/events.html