spacer

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

home / experts / javascript / column22


Passing Objects to Behaviors

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

A Behavior operates on an object that is associated with a DHTML element. In our Blinking Soccer example, we first define a Behavior named soccer in the scriptlet file, and then, by assigning it to the CLASS attribute, we associate a DIV element with this Behavior:


<DIV CLASS="soccer" ...

Once a Behavior is associated with a DHTML element, any operation inside the Behavior definition script is assumed to operate on the DHTML element's object. When you manipulate properties inside the soccer Behavior, for example, you actually manipulate the properties of the relevant DHTML object. The following lines from the soccer scriptlet change the visibility and position of the DIV object in the Web page:


style.position = "absolute";
style.pixelTop = x;
style.pixelLeft = y;

Referencing an object's methods is more complicated. Internet Explorer 5.0 does not default to the relevant DHTML object. Instead, it provides you with the uniqueID mechanism. The uniqueID is a unique ID of the DHTML object that is currently being operated by the Behavior. When we want to use the blink() method in our Blinking Soccer example, we call it as uniqueID+".blink()". When we want to schedule the blinking msecs milliseconds in the future, we use:


window.setTimeout(uniqueID+".blink()", msecs);

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

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