How do I use Jangaroo to convert a single As3 function to javascript?

569 views Asked by At

I've stumbled upon Jangaroo, and it seems to provide what i need. The problem is that to use it the docs say that i need to setup maven.

I really have a single function, so all that is a bit of an overkill.

The ideal solution would be something similar to the Telerik Code Converter(http://converter.telerik.com), but for AS3.

1

There are 1 answers

0
YetAnotherFrank On BEST ANSWER

I just updated the documentation on how to use Jangaroo as a command line tool:

https://github.com/CoreMedia/jangaroo-tools/wiki/Stand-Alone-Compiler

After following steps 1 through 6, you can compile your single class like so:

mkdir joo\classes
jooc -v -g SOURCE -classpath %JOOLIBS%\jangaroo-runtime.jar -sourcepath . -d joo\classes GACodec.as

Note that the generated JavaScript file GACodec.js only works together with the jangaroo runtime. The Wiki page continues with instructions on how to end up with a working Webapp. For your class, you just have to unpack jangaroo-runtime.jar:

"%JAVA_HOME%\bin\jar" -xf %JOOLIBS%\jangaroo-runtime.jar

Then, you can run your class from a tiny HTML file that looks like so:

<script src="joo/jangaroo-runtime.module.js"></script>
<script>
  joo.classLoader.import_("GACodec");
  joo.classLoader.complete(function() {
    alert(new GACodec().encode("FOOBAR!"));
  });
</script>

When trying out your code, I noticed that it needs a minor change to work: Jangaroo does not generate implicit initialization code for typed local variables. There are at least two lines in your code where an integer variable is declared but not initialized explicitly. ActionScript would set it to 0, but Jangaroo does not. Anyway, it is better style to do explicit initialization, and if you do so, i.e. in your source code replace

var i:int;

by

var i:int = 0;

as far as I can tell, it seems works!

Last thing, I find using Maven easier than installing the Jangaroo SDK, since you just have to install Maven once and it takes care of all needed downloads and makes updating to the latest Jangaroo version a breeze: Just increase the Jangaroo version number in your pom.xml, and Maven takes care of everything else.