If you go the route of using the server to compile javscript=>swf, you may need to modify the<br>server side eval response handler, because right now it is tailored to the debugger, so javascript strings are <br>compiled in this manner below. As you can see, it attempts to call Debug.write if it thinks the code is an<br>
expression with a return value. Otherwise it tries to treat it like a statement, with no return value to be printed.<br><br><br> public void compileAndWriteToSWF (String script, String seqnum, OutputStream out, String runtime) {<br>
try {<br> CompilationEnvironment env = makeCompilationEnvironment();<br> env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, true);<br> Properties props = (Properties) env.getProperties().clone();<br>
env.setProperty(env.RUNTIME_PROPERTY, runtime);<br> byte[] action;<br><br> // Try compiling as an expression first. If that fails,<br> // compile as sequence of statements. If that fails too,<br>
// report the parse error.<br> try {<br> String prog;<br> if (seqnum == null) {<br> prog = "(function () {\n" +<br> " #pragma 'scriptElement'\n" +<br>
"_level0.Debug.displayResult(\n"+<br> script + "\n" +<br> ");\n" +<br> "}());\n";<br> } else {<br>
// it's a remote debug request, send a response to client<br> prog = <br> "(function () {\n" +<br> " #pragma 'scriptElement'\n" +<br>
"_level0.Debug.displayResult(\n"+<br> " _level0.__LzDebug.sockWriteAsXML(\n"+script+","+seqnum+");\n" +<br> " );\n" +<br>
"}());\n";<br> }<br> prog += "this._parent.loader.returnData( this._parent );";<br> action = ScriptCompiler.compileToByteArray(prog, props);<br>
} catch (org.openlaszlo.sc.parser.ParseException e) {<br> try {<br> String wrapper =<br> " (function () {\n" +<br> " #pragma 'scriptElement'\n" +<br>
CompilerUtils.sourceLocationDirective(null, new Integer(0), new Integer(0)) +<br> script+"\n"+<br> " if (Debug.remoteDebug) { _level0.__LzDebug.sockWriteAsXML(true,"+seqnum+");};\n" + <br>
" }());\n" +<br> "this._parent.loader.returnData( this._parent )";<br> action = ScriptCompiler.compileToByteArray(wrapper, props);<br>
} catch (org.openlaszlo.sc.parser.ParseException e2) {<br> //mLogger.info("not stmt: " + e);<br> action = ScriptCompiler.compileToByteArray(<br> "with(_level0) {Debug.__write(" +<br>
ScriptCompiler.quote("Parse error: "+ e2.getMessage()) + ")}\n"<br> + "this._parent.loader.returnData( this._parent )", props);<br> }<br>
}<br><br> ScriptCompiler.writeScriptToStream(action, out, LPS.getSWFVersionNum(runtime));<br> out.flush();<br> out.close();<br> } catch (IOException e) {<br> mLogger.info(<br>
/* (non-Javadoc)<br> * @i18n.test<br> * @org-mes="error compiling/writing script: " + p[0] + " :" + p[1]<br> */<br> org.openlaszlo.i18n.LaszloMessages.getMessage(<br> Compiler.class.getName(),"051018-458", new Object[] {script, e})<br>
);<br> }<br> }<br><br><div class="gmail_quote">On Mon, May 19, 2008 at 9:15 AM, Marco Lettere <<a href="mailto:m.lettere@websynapsis.com">m.lettere@websynapsis.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Henry Minsky ha scritto:<br>
<div class="Ih2E3d">> This is a lot easier in DHTML runtimes than for swf runtimes, because<br>
> there is a javascript<br>
> interpreter built into DHTML runtime.<br>
<br>
</div>Yes I can see that.<br>
<div class="Ih2E3d">><br>
> You can just use "eval" to evaluate expressions. An equivalent of<br>
> constraints can be built at runtime, by registering<br>
> explicitly for events, but if you want to run the Laszlo constraint<br>
> analyzer to extract the dependencies out<br>
> of a javascript expression, it has to be done through the compiler.<br>
><br>
> The swf runtime has no Javascript interperter available to it, and<br>
> 'eval' does not really do anything useful, so<br>
> it is much more difficult to do what you describe. Our debugger in swf<br>
> actually sends javascript expressions back<br>
> to the LPS server, where they are compiled by our compiler. You could<br>
> do that too, using the same mechanism, I suppose. If you look at how<br>
> the debugger works, it sends a request to the server with the query<br>
> arg "lzt=eval" and "script=your-javascript-expression...", and it<br>
> returns a swf movie, that when loaded by loadMovie, will execute that<br>
> expression.<br>
><br>
</div>I thought about something like that but I didn't know about loadMovie.<br>
Sounds interesting I'll try to see if can put it to work in my context.<br>
Thank you.<br>
<font color="#888888">M.<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Henry Minsky<br>Software Architect<br><a href="mailto:hminsky@laszlosystems.com">hminsky@laszlosystems.com</a><br><br>