Friday, May 4, 2007

Convert ActionScript 2 to ActionScript 3

For a current Electrotank project we need to maintain a very large API as both ActionScript 2 and ActionScript 3. Early in the project Mike and I figured it would be easiest to maintain this API if we could just write it once (as AS2) and then just run a conversion tool when ever it is edited to upconvert it to AS3.

Mike wrote the tool and it works perfectly for what we're doing! This tool is great for code that doesn't deal with lots of things that are substantially different between AS2 and AS3. Basically that means if your classes deal much with UI or MovieClips then you might not find this tool as useful.

It automatically creates the package syntax, converts Void to void, recursively walks subdirectories, and outputs to a new location. In addition to those things it allows you to use two simple but powerful tags to do custom replacement of specific lines of code during upconversion. For instance:
//@replace var numShots:int = 10;
var numShots:Number = 10;


comes out as:
var numShots:int = 10;

Installation/usage instructions are included in the zip.
http://www.electrotank.com/junk/jobe/AS2_to_AS3.zip

I hope that some of you find this useful!

15 comments:

adampasz said...

Cool. I ran it on a big library of code, and it worked as described in the readme. Great for developing AS2 and AS3 concurrently, though probably not much use for updating old AS2 libraries.

One nice feature would be if it could add "void" to AS2 functions and methods that don't declare a return type.

Jobe Makar said...

Glad it works for you! The utility does convert Void to void, but won't add it. This works largely on just search and replace. So it doesn't really understand what a function is.

Anonymous said...

I can not find the document in the URL. Has been the utility dropped?

Jobe Makar said...

Hi,

It still exists but there is currently an outtage with our web server. Read about it here:
http://jobemakar.blogspot.com/2007/11/electrotank-and-electroserver-site.html

TheCanadianMeds said...
This post has been removed by a blog administrator.
TheCanadianMeds said...
This post has been removed by a blog administrator.
Magg said...

hello, I am very interesting about the utility, but the link (http://jobemakar.blogspot.com/2007/11/electrotank-and-electroserver-site.html)doesn't work,either.....can you post the right accurate URL? It will be helpful. PLZ~~

Jobe Makar said...

Hi,

I just checked the download link and it is working properly.

francesco di bonardo said...

i installed on vista and modified the run.dat. But after running the progamm, it deletes the two directory: As2output and AS3output.

Any clue ?

Anonymous said...

This does not work. It deletes the last 2 directories just like what was said in the previous post. No response means this is not real.

Anonymous said...

LOL stupid script does nothing else but delete the two created dir files.

Jobe Makar said...

Hi guys, I don't know what you're doing incorrectly, but the script does indeed work. We use it for every ElectroServer build!

Anonymous said...

The jar file actually attempts to delete other files. If the file is in use, it returns that it's unable to delete the file. Obviously there's something wrong with this.

JS said...

Jobe, I tried this on some code, and I followed your txt file, and it too deleted what was in my "AS2Output" and "AS3Output" folders. When I say delete, it removed the .fla's and swf's in that folder. I have my actionscript in an external folder in that directory. Please help! I'm a noob...

Anonymous said...

as others have pointed out, it does not work. I ran it and it just deleted the folders. Well, since it's free and all, I guess it doesn't matter. Maybe I'm doing something wrong... hmm, thanks anyway.