BS Contact J : JS-API : Emulate VrmlScript Nodes with Javascript

Sorry, your browser doesn't support Java.

This is an example to show how to emulate simple script behaviour with javascript.
Click on the laptop to see it opening/closing. According to the state of the laptop (opened or closed) a particular aninmation is started.

The Script node specified in the VRML Specification is especially usefull for this kind of state logic, but it is not supported by BS Contact J. By using the BS Contact J's JavaScript API you are nevertheless able to implement this kind of state logic by shifting your VRML script code to JavaScript on the HTML page. This sample should illustrate how this shifting can be done.
In this example the state logic should be triggered by user mouse clicks. We therefor have to set up a FieldScriptObserver listening to mouseclicks on the laptop.
In order to get the FieldScriptObserver to work properly we have to wait till BS Contact J has finished initialisation and loading of the world. This is done by the initialize method which is called during page loading.
By setting up the FieldScriptObserver we specify the event of interest and which JavaScript routine should be called when the event occurs.
The JavaScript function then performs the state handling and starts the appropriate animation.