start   previous   next

Shout3D™ 2.0 - Workflow Tutorial

Implementing in JavaScript

For a truly commercial project that runs smoothly and reliably on all platforms, we'd implement this toggle in Java by writing a custom applet. But to test out the concept quickly, we can plug it directly into an HTML page using JavaScript.

The complete script goes between <SCRIPT> tags in the <HEAD> section of the HTML page. It creates a variable named started and a function named toggle(). The toggle() function will be executed when the user clicks on a label.

<script language="JavaScript">

var started = false

function toggle() {
      var myTimer  =  document.shoutapplet.getNodeByName("TIMER");

      if (started == false) {

            myTimer.start();
            started = true;
      }
      else if (myTimer.isPaused() == false) {

            myTimer.setPaused(true);
      }
      else {myTimer.setPaused(false);}
}

</script>

We need a reference to the TimeSensor to store in the variable named myTimer. To get it, we use a method of the Shout3DApplet class called getNodeByName(). Take a look in the Method Summary for the Shout3DApplet class in the Javadocs to find this important method. You pass this method the DEF name of the node you are seeking, and it returns a reference to it. Recall that we gave our TimeSensor the DEF name TIMER in the scene file.

Next>


Copyright� 1999-2000, Eyematic Interfaces, Inc.