home previous
next contents![]() Shout3D 1.0 - User Guide
|
![]() |
Controlling Applets with JavaScriptJavaScript allows you to program behaviors into your Shout3D applet, right there in the html file. While it is not suitable for really big and complicated jobs, there is an awful lot you can accomplish simply by embedding some JavaScript code into your html file. There are a lot of things you can, but the following four examples give a good flavor for the possibilities. All of these are illustrated in the example javascript_demo.html. Making calls on the applet.You can call any method on the applet from JavaScript. The text 'document.Shout3D' refers to the applet, and following this you can call the method of your choice. For example, the Shout3DApplet class has a method getNodeByName(), documented right in this javadoc file. In the javascript demo, the Transform node containing the boxing mystery-man is a node named "BILL." It is retrieved as follows: var bill =
document.Shout3D.getNodeByName("BILL"); Setting and getting values in node fields.Once you've retrieved a node, you can set or get the value of any of its fields through JavaScript. Passing values that are arrays between JavaScript and Java is a little tricky, so methods are provided to ease the pain. Here are two quick snippets from the javascript example. (Note: the javascript also contains supporting functions, getFloatArrayValueFromString() and getStringFromFloatArray(), which you may want to copy into your own javascript file): Getting a translation value:var transString =
bill.translation.getValueByString(); Setting a translation value:var floatArray; Monitoring device input.Through JavaScript, you can register to have any method you like called when mouse or keyboard input is received. For example, to call a method "showXY" whenever mouse input occurs, this is all that is required: document.Shout3D.addJSDeviceObserver("MouseInput", "showXY"); Later, when the mouse input is received, the method showXY will be called and passed the mouseInput as a parameter. The information within the MouseInput is documented in the javadocs document right here. (Note: JavaScript Device observer methods should take one argument that is a DeviceInput parameter. ) Monitoring field values.You can also register to have a method called whenever a particular field changes. For example, if you'd like for the javascript method "billTranslationChanged" in your html page to be called whenever the translation field of the node named BILL undergoes a change, you'd make the following call: document.Shout3D.addJSFieldObserver("BILL", "translation", "billTranslationChanged"); Following this, all such changes will invoke the method "billTranslationChanged" with the new field value as an input. (Note: JavaScript FieldObserver methods should take one argument that is a field value. )
|