NADAV: This is a more specific question: Can a behavior-defined object receive events from other objects or behaviors? If so, how? Can a behavior define custom events? How would this work?
MICHAEL:First, I'll talk about how behaviors can source custom events.
We source custom events for the flyin behavior. In the declaration at the top of your component, you declare the event:
<EVENT id=finished name=onFinishedFly />
Then, when appropriate, you do the following in the behavior:finished.fire(evObj);
The fire() method is exposed on the event object declared at the top. You can cook up your own event object to pass with the event. This allows the behavior author to add custom properties to the event object.Behaviors have access to the document they are on, so they can synch any event on the document, or on any other element. We have added a new mechanism for synching events, however, which we call attachEvent(). The attachEvent() mechanism allows for multicasted events. For example, the flyin behavior "flies in" the content some specific time after the document loads. Without multicasting, if you had multiple flyin behaviors on a page, they would all clobber one other's attempt to synch the onload event. With the attachEvent() mechanism, each behavior can be notified when the window loads, without interfering with one other.
Attach event is simple:
window.attachEvent('onload', someFnPtr);
When the window onload event occurs, the function indicated by "someFnPtr" will be executed.The attachEvent() model is also really important for encapsulation. For example, the mask behavior needs to look at the onfocus and onblur events of the object it's attached to so that it can do the formatting. Because it uses the attachEvent() mechanism, however, the page author can also hook the onfocus or onblur events, yet not disrupt the behavior. Without this rich model for events, the behaviors event model would be very fragile, as well as hard for Web page authors to use and understand.
NADAV: Is there any security mechanism for scriptlet files? Can people just link to my scriptlet file from their page in some other domain or is there some way to stop them? Can I hide the code?
MICHAEL: Behaviors that come down over URLs can be loaded only from the domain that houses your page. It's possible for someone to point to it, but behaviors won't load from a domain other than that of the HTML page - in that sense it works just like cross-domain security. Also, to protect the script in the page, we have new "obfuscation" techniques that allow you to point to encoded script files.
In Conclusion
Sounds pretty good, no? Of course, since DHTML behaviors will only workin IE 5, it'll be some time before most Web developers can use them ontheir pages. Still, it seems more than likely that behaviors - orsomething very similar - will soon be a prized tool in every webmonkey'stoolbox.