December 23, 1999 - Passing Data to Behaviors | WebReference

December 23, 1999 - Passing Data to Behaviors

Yehuda Shiran December 23, 1999
Passing Data to Behaviors
Tips: December 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

A Behavior describes the dynamic appearance of HTML elements that are associated with the specified Behavior. As such, Behavior does not include data of its own. It needs to operate on data that is stored in the Web page. This data is passed to the Behavior through the named properties specified in the interface section of the scriptlet. The Automation type of <IMPLEMENTS> tag includes these properties:

<IMPLEMENTS TYPE="Automation">
<METHOD NAME="blink"/>

Notice the / at the end of each PROPERTY tag. It replaces the </PROPERTY> tag that one would expect to find at the end of the PROPERTY tag.

The property names specified in the scriptlet interface must match those in the DHTML elements. You can pick any names you want and as many properties as you want. In our example, we associate a Behavior with a DIV element. The x and y interface properties above are specified in the DIV definition as follows:

<DIV CLASS="soccer" x="200" y="250">

Inside the script section of the scriptlet, you can use interface properties like any other local variables. In our Blinking Soccer example from Column 22, DHTML Behaviors, we use the x and y properties to position a dynamic HTML element (DIV):

style.pixelTop = x;
style.pixelLeft = y;