Talk:Programmatically invoking a JavaFX Script
From Planet JFX
[edit] Compile errors
There appears to be some issues with the FxScriptLauncher:
1) InputStreamReader is unknown; resolved by adding "import java.io.InputStreamReader". 2) JavaFXProvisionClient cannot be resolved to a type. Not resolved...
Also note that issue 2 above is not resolved by either, downloading and including jar files from the JSR-000223 reference implementation or the latest versions of Java 6 from SUN.
For issue 2 you can use : InputStreamReader reader = new InputStreamReader(loader.getResourceAsStream("HelloWorld.fx"));
Of course HelloWorld.fx must be on your classpath.
- Removed JavaFXProvisionClient. I didn't use the loader option since that would require moving HelloWorld into the root of the classpath. -- Pforhan 14:23, 6 June 2007 (UTC)
Issue 2 Resolved with the change to the source of JavaFxScriptLauncher to FxScriptLauncher Now working with dynamic bindings.
[edit] How I can get something back from the script/scriptengine?
for example:
var win=Frame {
width:200
height:200
visible:true
};
var script:String="import javafx.ui.*;
var MyTestString=Button {
};";
var engine = new ScriptEngineManager().getEngineByExtension("fx");
var Object=engine.eval(script);
win.content=(Button) Object;
this does'nt work. bindings.get/put works only for plain java-objects. So how i can compose something with an external dynamical script and bind the result into the main script then?
cheers are
- The usage you show, above, is definintely not the norm. Generally, because of security issues, the JFX creators are hesitant to allow much in the way of dynamic invokation. I think you might be able to use JavaFX's built-in reflection protocol to invoke FX scripts dynamically, though I've not done it. Or, pick a java object to use as a communication point. Lastly (and this is one I've toyed with implementing) you could create a script dynamically, writing a script that references the scripts you are interested in, and then invoke that script the normal way. Pforhan 15:39, 31 January 2008 (UTC)