PDA

View Full Version : Action Script to Java Support


rossbleakney
03-23-2005, 03:59 PM
Are there any plans to add the ability to write or use Java code within a script block? I'm thinking of something similar to Jython (technically, it would be the opposite; Jython compiles Python to Java byte code while this new thing would compile Java to Flash byte code). Frankly, I'm afraid to make the jump to Laszlo for this reason. The language is fine, but I don't want to be without the great libraries that exist in Java (JDom, Jakarta, etc.).
Thanks,
Ross

edutf
04-26-2007, 04:52 PM
I'm not sure if you mean to access Java on the client side (browser) or in the server side (LaszloServer) of your laszlo application.

>> In the server side:

You are running a Tomcat (Java) in the server side, laszlo is just one more application deployed in this server. You can extend It in many different ways but the most commom are:

1) Use rpcconnection in the laszlo application to call methods in java classes deployed in the tomcat application.
2) Use a dataset with the url pointing to a JSP/Servlets that process methods in java classes in the server side and post the result back in XML format over the HTTP protocol.
3) I'm not sure if it's already implemented in laszlo, but in action script you can access java classes in the server by a RTMP connection. I know in laszlo 3.4.0 you find a rtmpconnection but I'm not sure if you are able to use this feature or RTMP connection is just to use streams of audio and video.

>> In the client side:

If you really want to execute some java process in your client side, (I'm wondering why, but maybe some encryption algoriphm or more complexy logic to be written in javascript, or even a stand alone application) you have a tricky way to do it. But to be short, follow these steps.

1) Use the lzt=html-object to run your laszlo app and generate a HTML page that runs your laszlo application (flash).
2) Write a java applet (you dont need to do any visual code on it, can be a "invisible applet" and post all function you want to acces in java on it. Put the <applet> tag somewhere in the page you got in the step 1.
3) Now you can use the LzBrowser.loadJS function in your laszlo application to call the applet in your html page as you do in normal javascripts in an html page.

The hardest part is the return, LzBrowser.loadJS executes the method but doenst give your the return. In order to get some return, do the following.

4) Change your applet java code to, instead of just return a value, call back a java script function in the html page that uses the browser integration capabilities of laszlo applications to set some attribute in the canvas. You can use the event onattributename in the canvas to be aware of this return.

Yeah, its tricky but once you do it in a smart way you can create a layer for this process and just use it as much as u want.

Would be nice to give a look in the JavaScript (normal html pages) and applet integration at the java website.

Good luck!!

Regards