ScriptListener Physlet
Drag the ball. Notice that JavaScript will update the table
whenever the ball moves. Drag the ball past negative 10 and observe what
happens.
The ScriptListener Physlet is designed to listen to a data source and invoke
a JavaScript function in response changes in the data source.
ScriptListener has been tested with the Animator Physlet but is still beta with
all other Physlets.
In order it to function properly on both Internet Explorer and Netscape,
careful attention needs to be paid to the following:
- The archive tag for the Physlet containing the data source and the archive
tag for the script listener must be exactly the same. For
example:
archive="Animator4_.jar,DataTable4_.jar,ScriptListener4_.jar,STools4.jar"
- The Applet tag for both Physlet must contain the mayscript
attribute.
- The ScriptListener Physlet should be disabled when the use leaves the html
page using the onunload event handler. This event handler is usually
defined within the body tag:
<body onload="initApplets()"
onunload="destroyApplets()">
- The ScriptListener Physlet is disabled by sending it an empty string using
the setJSFunction method in ScriptListener.
document.scriptlistener.setJSFunction("");
- The JavaScript function invoked by the ScriptListener should not call
other applets. If other applets need to be called, another JavaScript
function should invoked the the JavaScipt setTimeout fucntion to invoke a
callback.
timerID=setTimeout("myfunction()",50); //
myFunction will be called 50 msec later
The timerID is an integer that can can be used to interrupt the execution of
the myFunction. In order to make sure that myFunctioin is no longer
executing in the background when the html page unloads from memory, you should
call the clearTimeout function when the html page unloads. For
example, a typical appletDestroy JavaScript function should do the following:
function destroyApplets(){
clearTimeout(timerID);
document.scriptlistener.setJSFunction("");
}
The ScriptListner will respond whenever the data listener receives data, a
clearSeries, or a deteteSeries message from a data source. You can use
multiple ScriptListers that have been customized to respond to only certain data
source events using the following methods:
- setRespondToAddData( boolean)
- setRespondToAddDatum( boolean)
- setRespondToClearSeries( boolean)
- setRespondToDeleteSeries( boolean)