If you go the route of using the server to compile javscript=>swf, you may
need to modify the
server side eval response handler, because right now it is tailored to the
debugger, so javascript strings are
compiled in this manner below. As you can see, it attempts to call
Debug.write if it thinks the code is an
expression with a return value. Otherwise it tries to treat it like a
statement, with no return value to be printed.


    public void compileAndWriteToSWF (String script, String seqnum,
OutputStream out, String runtime) {
        try {
            CompilationEnvironment env = makeCompilationEnvironment();
            env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, true);
            Properties props = (Properties) env.getProperties().clone();
            env.setProperty(env.RUNTIME_PROPERTY, runtime);
            byte[] action;

            // Try compiling as an expression first.  If that fails,
            // compile as sequence of statements.  If that fails too,
            // report the parse error.
            try {
                String prog;
                if (seqnum == null) {
                    prog = "(function () {\n" +
                        "    #pragma 'scriptElement'\n" +
                        "_level0.Debug.displayResult(\n"+
                        script + "\n" +
                        ");\n" +
                        "}());\n";
                } else {
                    // it's a remote debug request, send a response to
client
                    prog =
                        "(function () {\n" +
                        "    #pragma 'scriptElement'\n" +
                        "_level0.Debug.displayResult(\n"+
                        "
_level0.__LzDebug.sockWriteAsXML(\n"+script+","+seqnum+");\n" +
                        " );\n" +
                        "}());\n";
                }
                prog += "this._parent.loader.returnData( this._parent );";
                action = ScriptCompiler.compileToByteArray(prog, props);
            } catch (org.openlaszlo.sc.parser.ParseException e) {
                try {
                    String wrapper =
                        "  (function () {\n" +
                        "    #pragma 'scriptElement'\n" +
                             CompilerUtils.sourceLocationDirective(null, new
Integer(0), new Integer(0)) +
                             script+"\n"+
                        "    if (Debug.remoteDebug) {
_level0.__LzDebug.sockWriteAsXML(true,"+seqnum+");};\n" +
                        "  }());\n" +
                        "this._parent.loader.returnData( this._parent )";
                    action = ScriptCompiler.compileToByteArray(wrapper,
props);
                } catch (org.openlaszlo.sc.parser.ParseException e2) {
                    //mLogger.info("not stmt: " + e);
                    action = ScriptCompiler.compileToByteArray(
                        "with(_level0) {Debug.__write(" +
                        ScriptCompiler.quote("Parse error: "+
e2.getMessage()) + ")}\n"
                        + "this._parent.loader.returnData( this._parent )",
props);
                }
            }

            ScriptCompiler.writeScriptToStream(action, out,
LPS.getSWFVersionNum(runtime));
            out.flush();
            out.close();
        } catch (IOException e) {
            mLogger.info(
/* (non-Javadoc)
 * @i18n.test
 * @org-mes="error compiling/writing script: " + p[0] + " :" + p[1]
 */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                Compiler.class.getName(),"051018-458", new Object[] {script,
e})
);
        }
    }

On Mon, May 19, 2008 at 9:15 AM, Marco Lettere <[EMAIL PROTECTED]>
wrote:

> Henry Minsky ha scritto:
> > This is a lot easier in DHTML runtimes than for swf runtimes, because
> > there is a javascript
> > interpreter built into DHTML runtime.
>
> Yes I can see that.
> >
> > You can just use "eval" to evaluate expressions. An  equivalent of
> > constraints  can be built at runtime, by registering
> > explicitly for events, but if you want to run the Laszlo constraint
> > analyzer to extract the dependencies out
> > of a javascript expression, it has to be done through the compiler.
> >
> > The swf runtime has no Javascript interperter available to it, and
> > 'eval' does not really do anything useful, so
> > it is much more difficult to do what you describe. Our debugger in swf
> > actually sends javascript expressions back
> > to the LPS server, where they are compiled by our compiler. You could
> > do that too, using the same mechanism, I suppose. If you look at how
> > the debugger works, it sends a request to the server with the query
> > arg "lzt=eval" and "script=your-javascript-expression...", and it
> > returns a swf movie, that when loaded by loadMovie, will execute that
> > expression.
> >
> I thought about something like that but I didn't know about loadMovie.
> Sounds interesting I'll try to see if can put it to work in my context.
> Thank you.
> M.
>



-- 
Henry Minsky
Software Architect
[EMAIL PROTECTED]

Reply via email to