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) :
When installed we have 7 demo applications to run from a Java project:
- 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
- A demo that displays an UML class diagram with standard
org.eclipse.draw2dobjects like Figure, Label etc...
- Draw2d example 2
- 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
- This demo display a tree diagram that you can dynamically build by yourself. It works for real I mean.
- An application with a slide menu that show off a list of Flickr images that you can click to zoom.
- What it says it is.
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.