mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
js mode example cleanups
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user