User Guide

246 APPENDIX E
Finally, it is possible to concatenate Webpage variable values into your command string sent to Atmosphere.
Once understood, this process is not diffi cult and is very useful to induce Atmosphere actions and changes based
upon events in the Webpage.
* See the examples elsewhere on the Atmosphere website to demonstrate this behavior in more detail. The
example can be downloaded and examined or customized for your particular application.
* Note: when modifying properties in in Atmosphere, its necessary to wrap the command in an eval() method,
as shown below. This requirement may be removed in the future.
//automatically hide the Atmosphere Chat pane
document.all.MetaCtl0.PluginCommand(“eval(application.chatPaneVisible = false);”, 0, 0);
//move a world object using a variable value from the webpage
document.all.MetaCtl0.PluginCommand(“eval(box.position = Vector(box.position[0], “ +
pageValue + “, box.position[2] ) );”, 0, 0);
sendJS(stringCommand)
This method allows Atmosphere world Javascripts to communicate with the Webpage Javascript. Any Javascript
code that the Webpage can process can also be triggered from an Atmosphere script. The entire document object
SceneGroup (DOM) can be addressed, functions can be called, properties changed, variables updated.
To accomplish any of these tasks, simply embed the identical Webpage call into a string within the
sendJS(stringCommand) method. Because the command is sent as a string, pay careful attention to how
embedded strings within your command are represented, since it is possible that they may incorrectly terminate
the command. As a reminder, there are two methods in Javascript for ensuring that multiple string quotations do
not cancel each other out. The fi rst is easier to visualize for syntax compliance, but as your command string gets
longer, the second method will become useful.
First Method: alternate the use of quotation types, as in “ . Here’s an example of a short command which is
easy to recognize as having correct syntax, and easy to send:
sendJS(“alert(‘Hello, World.’);”);
Second Method: use the backslash character “ \ “ prior to the embedded quotations. Using the backslash
character will instruct Javascript that the next character in line should be processed as part of the string, and
not a control character. The example shown here uses the same command example as above, but with different
formatting to help clarify the backslash use:
sendJS(“alert(\”Hello World.\”);”);
Both examples above will produce the same result in the Browser window (which is an alert dialog showing the
“Hello World. text). Again, depending upon the length of your command, both methods will be useful, with
longer command strings being more easily created with the second method.
Finally, it is possible to concatenate Atmosphere variable values into your command string sent to the webpage.
Once understood, this process is not diffi cult and is very useful to induce webpage actions and changes based
upon events in the Atmosphere world.