Icon

Random Stuff

AS3 in Linux – Part 2

two years after this post, what is the state of AS3 development under Linux?

Well, I will tell you upfront, it is looking much brighter.

Let us review what is needed:

  1. A nice IDE with code completion and project management
  2. A debugger for tracing output
  3. A compiler for creating swfs (if other formats are available, that would be nice too)

If you are looking for a decent setup under Ubuntu 10.04 (or 10.10), read along.Ste

Step 0 – For the Lazy

Quick version, for folks that dont wanna read:

  • Get  Eclipse from the repo, add
    • xtext – http://download.eclipse.org/modeling/tmf/updates/releases/
    • axdt – http://svn.codespot.com/a/eclipselabs.org/axdt/trunk/site/
    • install axdt and required dependencies
  • get DeMonsterDebugger for tracing

Step 1 – IDE

  • Get eclipse from the repos.
  • Go to help > Install New Software
  • Select "all available sites"
  • search for "xpand"
  • install it.
  • While it downloads, go to "window>preferences", select "install/update>available software", click on "add"
  • Add http://download.eclipse.org/modeling/tmf/updates/releases/, call it "xtext" (or whatever you want)
  • Add http://svn.codespot.com/a/eclipselabs.org/axdt/trunk/site/, call it "AXDT" (or whatever tickles your fancy)
  • restart Eclipse
  • Go to help > Install New Software
  • select – All Available Sites – , filter for axdt
  • check everything
  • filter for "xtext", check Xtext SDK
  • next
  • wait a bit

Congratulations, you have a working IDE!

Other options are available, but I ain't Google. I am proposing a solution that works. And yeah, I am not fond of Eclipse either, and I would really like to have FlashDevelop available, but FD does not work on Linux-based stuff, not under wine, not under any conditions.

In case you would like to know what you just installed: AXDT is a workspace that allows for AS3 coding; xtext is a library AXDT needs.

Step 2 – Debugger

Let us be frank and honest here: I haven't searched really well. I found a way to trace output, and it is enough for me. I am used to work on PHP scripts without any Xdebug available and thus I am used to work out my own solutions for tracing data. So no real debugger, just a tracer.

The following is directly copy-pasted from there:

  1. Ensure that Adobe AIR is installed. If not, install from http://get.adobe.com/air/
  2. Install De MonsterDebugger from http://demonsterdebugger.com/downloads
  3. Launch it
  4. Choose File > Export Client Class
  5. Locate the src folder of your Flash project in your Eclipse workspace
  6. Click Select to output the necessary debugger classes to your Flash project
  7. Import the necessary classes:  import nl.demonsters.debugger.MonsterDebugger;

Now you can do:

debugger = new MonsterDebugger(this);MonsterDebugger.trace(this, "Hello World!");

Step 3 – Compiler

Here, you have two basic options: Flex Builder, or Flex SDK. Flex builder comes with more features, but I would be at loss if you ask me which, coz it costs money whereas Flex SDK is free, and I like free.

IMPORTANT: If you are skimming through the article, please stop and read this: This is here in case you want to install the Flex SDK on your own. If you are already using Eclipse + AXDT, then you ALREADY have Flex SDK, and you can just skip Step 3.

So if you are sticking with this tutorial, it is the Flex SDK that you are going to use.

  1. So first, get the Flex SDK from there. Adobe has a habit of changing their URLs, so if you get the wrong page, no worries, just google it.
  2. Make sure you have Java 6 SDK (sudo apt-get install sun-java6-jdk)

For convenience, edit your ~/.bashrc  (for the freshly converted, that means /home/your-username/.bashrc), and add those lines:

[codesyntax lang="bash" lines="no"]

#replace '/opt/flex-sdk' by your own path where flex can be found

export FLEX_SDK_HOME=/opt/flex-sdk

alias mxmlc='/usr/lib/jvm/java-6-sun/bin/java -jar "$FLEX_SDK_HOME/lib/mxmlc.jar" +flexlib="$FLEX_SDK_HOME/frameworks" "$@"'

[/codesyntax]

Or, instead of creating an alias for mxmlc, add this to simply add flex to your global paths (in  ~/.profile).

[codesyntax lang="bash" lines="no"]

export PATH=$PATH:/opt/flex-sdk/bin

#do not forget to NOT insert a space around the "="!

[/codesyntax]

Any of those two syntaxes will allow you to compile SWFs from commandline by typing "mxmlc youFlexApp.mxml" instead of the full path each time (tip copy-pasted from there).

Step 4 – Testing

Let's try this! create a new file, call it whatever:

[codesyntax lang="mxml" lines="no"]

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button label="I am a simple flexy button" x="10" y="10" />
</mx:Application>

[/codesyntax]

From command-line:

[codesyntax lang="bash" lines="no"]mxmlc whatever.mxml[/codesyntax]

Let the compiler work its magic, then:

[codesyntax lang="bash" lines="no"]firefox flexTest.swf[/codesyntax]

If you want to create a pure AS3 project, this is a hello world code

[codesyntax lang="actionscript3" lines="no"]

package {
import flash.display.Sprite;
import flash.text.TextField;
public class Application extends Sprite {
public function Application() {
var tf:TextField = new TextField();
tf.width = 200;
tf.text = "Hello World!"
addChild(tf);
}
}
}

[/codesyntax]

It works!

Step 6 – Optional & Further Info

  • You can get the Air SDK there http://www.adobe.com/products/air/sdk/
  • Another option for Eclipse is FB4Linux. Have not tested it. Google told me AXDT was preferred, and I tend to go with the tool that has the largest community. If you want to give it a shot, I hear this tutorial is nice (as read there).
  • If you'd rather use Netbeans (I know I do), you can try the Flexbean plugin. But then you have to download the Flex SDK separately as described in step 3.  Then go to Tools > Flex Platform > Add and add the path to your Flex SDK. Note that Flexbeans, at the time of writing, does not support syntax highlighting or auto-complete; it only allows you to create flex-type projects, and to compile them from Netbeans. Also, I could not get it to work. It installs fine and all, builds execute, but nothing is displayed when I open the swf file. I tried both mxml project and AS3 project to no avail. If anyone has pointers…Please comment
  • Did you notice there is no step 5?
  • You can also use haXe to generate SWFs. HaXe claims they have a very good performance. I haven't benchmarked myself, so I could not tell. If you want to use haXe, just get it from the repos, then get the plugin for Eclipse (info here). Sadly, no plugin for Netbeans, but a lot of plugins are available for a lot of IDEs, just check if the one you like is there.
  • Last but not least, a nice IDE is available there, it is called Flash MiniBuilder and it is built entirely in air, so completely cross-platform. For it to work, you will need also to download this, and run it each time before miniBuilder. I'd advise writing a bash script to make things easier.
  • If you are wondering where to go from there, this page has a nice comprehensive list of the most important and useful AS3 libraries. Almost all those I have ever used or came across are there anyway.

When it is all said and done, I must say although there are viable solutions today for AS3 coding under Linux, I still dearly miss FlashDevelop. I really wish they would do a mono version at least.

Comments and suggestions are more than welcome.

by

Category: Articles

Tagged: , , , , , , , , ,