js mode example cleanups

This commit is contained in:
fjenett
2011-06-18 19:37:00 +00:00
parent adeb692223
commit 87deeaa360
16 changed files with 129 additions and 144 deletions
@@ -1,5 +1,6 @@
/**
* This example demonstrates how to promt for user input
* This example demonstrates how to promt for user input. It first asks
* for password which then is used to unlock the sketch.
*/
String password = null;
@@ -94,15 +95,17 @@ boolean testLocked ( String passTry )
}
// this is needed to define a way for us to be able to call out
/* this interface is needed to explain Processing what the
properties of the object are that is handed in from JS */
interface JavaScript
{
String promtForInput( String message, String defaultAnswer );
}
// a variable
JavaScript js;
// called from JavaScript to hand in the object
void setJS ( JavaScript jsi )
{
js = jsi;
@@ -1,16 +1,19 @@
// wait for document to load
window.onload = function () {
tryFindSketch();
}
// find sketch instance
function tryFindSketch () {
var sketch = Processing.instances[0];
if ( sketch == undefined )
return setTimeout( tryFindSketch, 200 ); // try again in 0.2 secs
sketch.setJS( this );
setTimeout( tryFindSketch, 200 ); // try again in 0.2 secs
else
sketch.setJS( this );
}
// called from inside the sketch
function promtForInput ( msg, def ) {
return window.prompt( msg, def );
}