Re: Events with parameters in windows script components by mr_unreliable
mr_unreliable
Mon Jul 07 11:09:04 CDT 2008
This is a multi-part message in MIME format.
--------------070408000600050207020107
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
vorpal wrote:
> Any help appreciated...
> --Vorpal
Vorpal, I'm not sure how to answer your direct question,
but if you read the wsc documentation, then you will find
a different way of passing back event parameters, i.e.,
by using the oEvent "Event Object" created via the
"CreateEventObject" method.
Look up the "fireEvent Method" in the "microsoft windows
script component" documentation. You can (probably) find
the documentation somewhere on the microsoft scripting
website, but I have attached a copy of that page (in html
-- hope it can be read o.k., and if not I'll just send
it in text).
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
--------------070408000600050207020107
Content-Type: text/html; charset=ISO8859-1;
name="fireEvent.html"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="fireEvent.html"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title>fireEvent method</title><style>@import url("MS-ITS:dsmsdn.chm::/html/msdn_ie4.css");</style>
<link rel="stylesheet" href="MS-ITS:dsmsdn.chm::/html/msdn_ie3.css">
<meta NAME="MS-HKWD" CONTENT="Behavior handler reference">
<meta NAME="MS-HKWD" CONTENT="fireEvent">
<meta NAME="MS-HKWD" CONTENT="fireEvent Function">
<meta NAME="MS-HKWD" CONTENT="fireEvent function, Behavior script components">
<meta NAME="MS-HKWD" CONTENT="firing events (Behaviors)">
<meta NAME="MS-HKWD" CONTENT="sending events (Behaviors)">
<meta NAME="MS-HAID" CONTENT="letmthfireEventBHV">
<meta NAME="MS.LOCALE" CONTENT="EN-US">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<meta NAME="PRODUCT" CONTENT="Windows Script Components">
<meta NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<meta NAME="CATEGORY" CONTENT="Behavior Handler Reference">
<meta NAME="Description" CONTENT="fireEvent method">
<meta NAME="Keywords"
CONTENT="Behavior handler reference; fireEvent function, Behavior script components; firing events (Behaviors); sending events (Behaviors)">
</head>
<body BGCOLOR="FFFFFF" LINK="#0033CC">
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<font FACE="Verdana, Arial, Helvetica" SIZE="2">
<table BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
<tr VALIGN="TOP">
<td WIDTH="360"><font SIZE="1" COLOR="#660033">Microsoft® Windows® Script Component</font><br>
<font SIZE="5" COLOR="#660033"><b>fireEvent Method</b></font></td>
<td ALIGN="RIGHT"><font SIZE="2"> <a HREF="letBHREF.htm">Behavior Handler Reference</a><br>
</font></td>
</tr>
</table>
<p><a HREF="letmthfireEventBHVC.htm">See Also</a>
<hr noshade SIZE="1">
<BLOCKQUOTE>
<p>Fires a custom event.</p>
</BLOCKQUOTE>
<p class="blue"><b>Syntax</b></p>
<BLOCKQUOTE>
<p><i>Behavior</i>.<b>fireEvent</b>(<i>sEvent</i>[, <i>oEvent</i>])</p>
</BLOCKQUOTE>
<p class="blue"><b>Values</b>
<BLOCKQUOTE>
<dl>
<dt><i>Behavior</i> </dt>
<dd>The ID of the <implements> element used to implement the Behavior interface. <p
class="atl"><b>Note </b>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 <i>Behavior</i>.fireEvent
as shown in the syntax, the property can be used in script simply as fireEvent. For more
details, see the <a href="leteleimplements.htm"><implements></a> element.</p>
</dd>
<dt><i>sEvent</i> </dt>
<dd>The name of the custom event as declared in the <implements> element. </dd>
<dt><i>oEvent</i> </dt>
<dd>(Optional) Specifies an event object containing context information. The event object is
created using the <a href="letmthcreateEO.htm">createEventObject</a> method. </dd>
</dl>
<b>
</BLOCKQUOTE>
<p>Remarks</b></p>
<BLOCKQUOTE>
<p>The same event object cannot be reused in multiple calls to the fireEvent method.</p>
</BLOCKQUOTE>
<p class="blue"><b>Example</b></p>
<BLOCKQUOTE>
<p>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.</p>
<p class="indent"><b>Note</b> A CDATA section is required to make the
script in the <script> element opaque. For details, see <a href="letXML.htm">Script Component
Files and XML Conformance</a>.</p>
<PRE><FONT FACE="Courier New" SIZE=3><code><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;
<span
class="cfe"><b>fireEvent("onResultChange",oEvent)</b></span>;
}
]]>
</script>
</component>
</code></PRE></FONT>
<p>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 <code>result</code> of the window.event object and displayed in the resultWindow
<DIV> element.</p>
<PRE><FONT FACE="Courier New" SIZE=3><code><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>
</code></PRE></FONT>
</BLOCKQUOTE>
<hr noshade size=1>
<!--COPYRIGHT BEGIN--><!--COPYRIGHT END-->
</FONT>
</BODY>
</HTML>
--------------070408000600050207020107--