fireEvent method (Behavior Handler Reference)
Fires a custom event.
Syntax
Behavior.fireEvent(sEvent[, oEvent])
Values
Behavior
The ID of the <implements> element used to implement the Behavior interface.Note
By default, the properties and methods exposed by the Behavior handler are automatically added to the global script namespace and can be accessed without referencing the Behavior handler ID. In this case, instead of using Behavior.fireEvent as shown in the syntax, the property can be used in script simply as fireEvent. For more details, see the <implements> element.
sEvent
The name of the custom event as declared in the <implements> element.oEvent
(Optional) Specifies an event object containing context information. The event object is created using the createEventObject method.
Remarks
The same event object cannot be reused in multiple calls to the fireEvent method.
Legacy Code Example
The following partial script component is derived from a calculator script component sample. Whenever the result changes, the script component fires a custom onResultChange event back to the page, passing the result as an expando property of the event object.
Note
A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<component>
<public>
<event name="onResultChange" />
</public>
<implements type="Behavior">
<attach event="onclick" handler="doCalc");
</implements>
<script language="JScript">
<![CDATA[
function doCalc(){
// Code here to perform calculation. Results are placed into
// the variable sResult.
oEvent = createObjectEvent();
oEvent.result = sResult;
fireEvent("onResultChange",oEvent);
}
]]>
</script>
</component>
The following shows what the containing DHTML page might look like. When the onResultChange event fires, the results of the calculation are extracted from expando property result of the window.event object and displayed in the resultWindow <DIV> element.
<HTML>
<HEAD>
<xml:namespace prefix="LK" />
<style>
LK\:CALC {behavior:url(engine.wsc)}
</style>
<script language="JScript">
function showResults(){
resultWindow.innerText=window.event.result;
}
</script>
</HEAD>
<LK:CALC id="myCalc" onResultChange="showResults()">
<TABLE>
<TR>
<DIV ID=resultWindow
STYLE="border: '.025cm solid gray'"
ALIGN=RIGHT>0.</DIV>
</TR>
<TR>
<TD><INPUT TYPE=BUTTON VALUE=" 0 "></TD>
<TD><INPUT TYPE=BUTTON VALUE="+/-"></TD>
<TD><INPUT TYPE=BUTTON VALUE=" . "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" + "></TD>
<TD><INPUT TYPE=BUTTON VALUE=" = "></TD>
<TR>
</TABLE>
</LK:CALC>
</HTML>