E4 SWT Java for Flash: running the demos

Eclipse E4 ActionScript development environment screenshot

Eclipse foundation recently have released Eclipse E4 Milestone 1 with the support of so called ActionScript development environment for SWT. It means that you can now export Java applications for the Flash Player. There is some pretty good instructions to run some demos. I've played with it last night. This post is intended to give you a quick overview of the whole thing with an ActionScript developer point of view.

The installation process is easy. You mainly have to download Eclipse SDK 3.5M4, install some updates, the Adobe Flex SDK 3 and configure the Eclipse environment. It takes less than an hour if you have a good connection and sufficient knowledge of what we are talking about. Just do not forget anything and cross your finger, as the E4/SWT team said: "[..] both the tools and the port are in the pre-alpha stage. You are living on the bleeding edge. Good luck!".

Here is what the Eclipse E4 environment looks like when the examples project is opened (note that the tests were done on Windows XP 32) :

what the Eclipse E4 environment looks like when the examples are selected

When installed we have 7 demo applications to run from a Java project:

ControlExample
controlexample application screenshot
SWT controls demo, with 25 controls to test and plenty of parameters to change for each. All the components displayed are those from the Flex SDK wrapped by an SWT container to manage event, styles etc...
Draw2d example 1
Draw2d example 1 screenshot
A demo that displays an UML class diagram with standard org.eclipse.draw2d objects like Figure, Label etc...
Draw2d example 2
Draw2d example 2 screenshot
This example show us a similar demo than the first, but boxes from the UML diagram can be dragged and the connector automatically follow.
Draw2d example 3
Draw2d example 3 screenshot
This demo display a tree diagram that you can dynamically build by yourself. It works for real I mean.
FlickrViewer
FlickrViewer screenshot
An application with a slide menu that show off a list of Flickr images that you can click to zoom.
HelloWorld
What it says it is.
STDemo
An example to demonstrate that the application can communicate with its host, here Flash to Javascript.

How it works

To summarize, all the code here is Java code. None of the examples use reference to Flex SDK code nor Flash Player specific code, even the one that displays Flex controls. It all uses SWT code with its specific API.

Each example use a generic SWT wrapper written in Java and exported in ActionScript that control at runtime the access to standard Flash/Flex specific code. The code (not sure if it is the whole code) of this wrapper can be found in workspace\org.eclipse.swt\Eclipse SWT\flex\org\eclipse\swt\widgets. To summarize the wrapper works with shunts like : RadioButton button = new intrinsic.mx.controls.RadioButton(); where RadioButton will be the RadioButton used by the wrapper, not directly by the user. The user will use instead org.eclipse.swt.widgets.Button.Button, the wrapping magic is hidden, each call to one of its property will be converted in a call that the Flex SDK wrapped Button will understand.

What you may want to know, is you need to add a JRE to your Eclipse Environment that is called "Java 1.5 for ActionScript (J2AS-1.5)" what I believe to be first the J2AS project from osflash.org, but it is not. What I understand here is it means that each line of code you wrote will not be managed by the Standard JRE but by this specific "Java 1.5 for ActionScript" JRE. It seems to mainly uses a named "actionscriptJCL.jar" located in Eclipse environment plug-ins dir.

Running a Flash application

Before you can launch the demos you need to set your Intenet Explorer or Firefox directory. So when you debug the projects, applications run in the browser of your choice. When launched in debugging mode, the Flash player debugger connects to the Java debugger and it works as you are used to with the Flex debugger! It means that you can see the "internals" of the running application. All associated to Java code only. You still never see any ActionScript code here, even any stub code.

I have quickly tested to launch JProfiler, it seems not possible to connect it to the demos even in debugging mode when the Eclipse debugger is used. To be honest I don't know how profiling junction to debugger works in Eclipse. So I don't know if it is possible to profile a Flash application even from the ActionScript development environment for SWT.

The bad news

Now the bad news is when exploring the generated SWF files for each demo, we can see that what I call the SWT ActionScript wrapper is a SWF file named org.eclipse.swt.swf that weighs 960KB, common code for the examples 160KB and other files make any of the demo launched to load something like 2MB before to launch. It excludes to use any SWT generated application on any high audience public website.

I have not thought much about this, but I can't see any problem to compile a Java application for Air from SWT. Finally as Air is local only, it could be the only interesting usage for this project since library sizes are so important.

Worth a try

I can't give you any link to an online demo because when compiled each application load its dependencies (the incriminated fat SWF files) with a URL prefixed by http://localhost:7777/actionscript?path=c:/therealpathto/yourfile.swf. And it seems hardcoded and actually don't know how to bypass this limit. I will try to update this post if I can find or if any of my reader can find a way to bypass this.

So even if the weight of a whole application is a bad news, it is worth a try. Hope this helps.

You may be also interested in reading Eclipse E4 M1 SWT: JAVA to AS3 blog post from Ted Patrick.

20 thoughts on “E4 SWT Java for Flash: running the demos

  1. If we assume that this project can generate libraries as SWF or SWC. I suppose that we can ask any Flash application to compile while using the code generated from Java and located in the SWF/SWC used as libraries.

  2. I follow the instructions and get to this point:
    2. Download the SWT source zip from the latest download page (The zip is named org.eclipse.swt.e4.flex-I[timestamp].zip).
    but cannot find the file to download…. please can anyone point me in the right direction?

  3. Hi Tek, thanks a bunch for the help, excellent. I got as far as compiling/trying to run the examples but just got loads of errors. Guess this is pretty bleedin edge stuff! I’ll look again at the weekend.

  4. @Grimesters> You normally have “only” 1851 warnings but no errors at all. Are you sure not have forgiven to configure what they call the “ActionScript VM” ? I had plenty of errors too when first missed this step.

  5. Pingback: A-SFUG: Another Singapore Flash User Group » Eclipse E4 & SWT: A Real Flash/Flex Killer

  6. You can access it via : Preferences>Java>Installed JREs.

    All is explained at the fourth step of “Setup the Eclipse target environment”.

    Let me know if it works for you.

  7. Yes, i just follow the steps

    Add a new ActionScript VM. (‘Window’ -> ‘Preferences’ -> ‘Java>Installed JREs’).

    1. Click Add…
    2. Select ActionScript VM, click next.
    3. Click Directory… and browse to either your Firefox or IE install directory.
    4. Click OK.
    5. Click Finish

    in the step 2. Select ActionScript VM, click next. i cannot find “ActionScript VM” this option, only standard VM …., and what is ActionScript VM?

  8. For the flex setup,
    i set JAVA_HOME env var for my java_home, C:\Program Files\jdks\jdk1.6.0_02
    add the following line at the end of eclipse.ini
    -Dflex.sdk=E:/Java/dev/eclipse-jee-ganymede-3.4-FB3/eclipse/FlexBuilder3/sdks/3.0.0

    and i use eclipse-SDK-3.5M4-win32, so SWT ActionScript tools should already be there.

  9. Gembin I think that your error is that even SDK-3.5M4 needs org.eclipse.swt.e4.flex-I[timestamp].zip archive, it’s why you don’t have Actionscript VM that appears right in the window we’re talking about previously.

  10. Yes, i downloaded org.eclipse.swt.e4.flex-0.9M1.zip, but it is source code not a JAR binary .

    and i already imported Existing projects into workspace as the instructions said.

    BUT, i think there should be eclipse plugins for org.eclipse.swt.e4.flex which should be put to the eclipse plugins dir, and i cannot find it.

  11. Very nice introduction and review! I am also trying to follow the steps and run the demo. But where can I downlaod the J2AS-1.5 from?

    James

  12. @James As I can remember it is not something you have to download. It must be here when you have installed the SWT ActionScript development tools.

  13. I’ve also a question about the ActionScript VM (Run as …) I tried all the versions of e4 and I’m not be able to setup ActionScript VM. I followed all the steps at http://wiki.eclipse.org/E4/SWT/Running_the_demos more than five times(on all Milestones and release candidates).

    Entry eclipse.ini
    -Dflex.sdk=C:/dev/swtflex/Flexsdk
    it points to the Adobe open source Flex SDK

    Hopefully you have some hints for me …

  14. I’ve the same problems. I can’t find the ActionScript VM.

    What i’ve done:

    1 Download the e4 build 0.0

    http://download.eclipse.org/e4/downloads/drops/R-0.9-200907291930/index.html#EclipseE4

    2 install new software

    http://download.eclipse.org/e4/downloads/drops/R-0.9-200907291930/repository

    => Eclipse e4 ActionScript Developer Tools (Incubation) .9.0.v20090609-1530-47L-9oB55W5I5O28OE5

    => Eclipse E4 SWT ActionScript Source (Incubation) 0.9.0.v20090609-1530-47L-9oB55W5I5O28OE5

    3 install the flex incubation (export into the current project)

    org.eclipse.swt.e4.flex-incubation-0.9.zip

    4 shutdown eclipse and manipulate eclipse.ini

    Entry eclipse.ini
    -Dflex.sdk=C:/dev/swtflex/Flexsdk

    ————————

    So know everybody how we can bring this e4 with flex to run ?

    i’ve more questions

    1 what to hell is => Select Project>Popup Menu>Action Script Tools>Toggle Nature.
    2 where i must (Add the org.eclipse.swt project to the Java Build Path) / to the source tab ?
    3 Change the execution environment of the project JRE container to J2AS-1.5 / why i can’t see the J2AS-1.5

    4 Preferences’ -> ‘Workspace’ -> ‘Linked Resources’/ where can i find this one.

    whoever have a full working eclipse(swt to flex) installation it’s possible to zip the full directory and put this on my server ? i can set this free for everybody

    thanks

    send me a message to von_schrenk@yahoo.co.uk then we can arrange this.

  15. @Frank

    Select Project>Popup Menu>Action Script Tools>Toggle Nature is a standard Flex Menu. In Flex it is used to convert a standard ActionScript Project to a Flex SDK project. You don’t need it now for sure.

    Sorry, but I do not have the Eclipse environment that runs with E4 SWT anymore. I cannot upload you the archive.

    Another thing that will make it harder is that I think the article http://wiki.eclipse.org/E4/SWT/Running_the_demos has been modified since I wrote this post. at least it means that now this page is up to date for the last Eclipse build. Cannot help you more.

  16. Compilation error while compilation java project on e4 environment
    (Where JavaAs in my java project)
    What will the output of java project compilation on e4 environment?

    Errors occurred during the build.
    Errors running builder ‘Java Builder’ on project ‘org.eclipse.swt.e4.jcl’.
    org.eclipse.jdt.internal.compiler.lookup.MethodBinding.getHighestOverridenMethod(Lorg/eclipse/jdt/internal/compiler/lookup/LookupEnvironment;)Lorg/eclipse/jdt/internal/compiler/lookup/MethodBinding;

    Errors running builder ‘Java Builder’ on project ‘org.eclipse.swt’.
    org.eclipse.jdt.internal.compiler.lookup.MethodBinding.getHighestOverridenMethod(Lorg/eclipse/jdt/internal/compiler/lookup/LookupEnvironment;)Lorg/eclipse/jdt/internal/compiler/lookup/MethodBinding;

    Errors running builder ‘Java Builder’ on project ‘JavaAs’.
    flash/tools/debugger/PlayerDebugException

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>