262Part IIIDocument Objects ReferenceListing 15-19a(continued) function makeNormal() (Web hosting ratings) {

262Part IIIDocument Objects ReferenceListing 15-19a(continued) function makeNormal() { if (event.srcElement == element) { runtimeStyle.color = oldColor; } } The object to which the component is attached is a simple paragraph object, shown in Listing15-19b. When the page loads, the behavior is not attached so clicking the paragraph text hasno effect. When you turn on the behavior by invoking the turnOn()function, the addBehavior() method attaches the code of the makeHot.htccomponent to the myPobject. At this point, the myPobject has one more property, one more method, and two more event handlers thatare written to be made public by the component s code. If you want the behavior to apply tomore than one paragraph in the document, you have to invoke the addBehavior()methodfor each paragraph object. After the behavior file is instructed to start loading, the setInitialColor()function iscalled to set the new color property of the paragraph to the user s choice from the selectlist. But this can happen only if the component is fully loaded. Therefore, the function checksthe readyStateproperty of myPfor completeness before invoking the component s function. If IE is still loading the component, the function is invoked again in 500 milliseconds. As long as the behavior is loaded, you can change the color used to turn the paragraph hot. The function first ensures that the component is loaded by checking that the object has thenew color property. If it does, then (as a demonstration of how to expose and invoke a com- ponent method) the method of the component is invoked. You can also simply set the prop- erty value. Listing 15-19b: Using addBehavior() and removeBehavior()