ok. no problem. sure you can add the callback to a Processing sketch:
create a new sketch and copy the following into it:
Code:
void setup ()
{
JSCallback.jsCallback( "alert(\"test\");", this );
}
in that sketch create a new tab, name it "JSCallback.java" and copy the following into it:
Code:
import processing.core.*;
import java.applet.*;
class JSCallback
{
static void jsCallback ( String _jsCommand, PApplet _papplet )
{
if ( !_papplet.online ) return;
try {
Class c = Class.forName("netscape.javascript.JSObject");
java.lang.reflect.Method getWin = c.getMethod("getWindow",new Class[]{ java.applet.Applet.class } );
java.lang.reflect.Method eval = c.getMethod("eval",new Class[]{ String.class } );
Object jswin = getWin.invoke(c, new Object[]{ _papplet } );
if ( jswin != null )
eval.invoke( jswin, new Object[]{ _jsCommand } ).toString();
return;
} catch (Exception e) { ; }
try {
java.applet.AppletContext context = _papplet.getAppletContext();
if ( context != null ) {
context.showDocument( new java.net.URL("javascript:" + _jsCommand) ,"_self" );
}
} catch (Exception e) { ; }
}
}
save, press export (export for web) and open the index.html file in your browser. you should get an alert window with the text from setup ...
param is a way to _read_ params from the html-file that contains the applet. it's a simple way to pass variables to an applet. these can only be set before the applet has loaded and will not change the html or execute any javascript.
forget open(), use link() instead. it will open an url in the browser if you pass one to it.
if you want to have the flash-movie replace the applet you will have to use javascript. link() ( or open() ) will reload the contents of the window or open a new one ...
F