AS2 to AS3 preprocessor converter - first draft

Posted on Tuesday 14 November 2006

After yesterday’s heated discussion as to the actual usefulness of an AS2 to AS3 converter, I decided to implement some of the features in laundry list to see if I could get something actually useful. You can test it live here. You can download the PHP source here. The source includes convert.php, which expects two folders, src and output, with src containing source .as files, and output being where the output files will be written (this feature is not in the online version for obvious reasons).

So, here is a list of what it currently does:

  • Detects package, adds appropriate package keyword, and adds tabs to body of the class
  • Does a find and replace of changed keywords, for example Void to void, beginFill to graphics.beginFill, private to protected, _x to x, _xmouse to mouseX, Camera.get to Camera.getCamera, etc.
  • Adds imports for MovieClip, clearInterval, setInterval, getTimer, Camera, Video, Microphone, etc.
  • Strips Delegates when first argument is this

There is a come working code in the ClassParser.php file that changes createEmptyMovieClip, createTextField and getURL to their new equivalents, with some advanced parsing for function arguments and the like, but it needs a little more work, and after some thoughtful consideration, I decided not to pursue this any further as the amount of work required did not seem worth it. In particular, for the createEmptyMovieClip function, how should I know that what you want to create is a new MovieClip, instead of a Sprite or a SimpleButton for example? That would require semantics and at that point you should probably take the time to figure out yourself. If you want to take a shot at it however, you’re more than welcome to modify the code. I had thought of writing the thing in C# so it would be more practical to deploy but since I have very little time I decided to opt for the more familiar PHP.

As it is however, although it’s little more than an elaborate batch of regex, it’s pretty useful. Running the script through it all my ARP commands now compile as AS3, some views are pretty close to compiling, some are quite far, but I saved quite some time in the end with this simple scheme. Enjoy.


WordPress database error: [Can't open file: 'wp_comments.MYD'. (errno: 145)]
SELECT * FROM wp_comments WHERE comment_post_ID = '224' AND comment_approved = '1' ORDER BY comment_date

No comments have been added to this post yet.

Leave a comment




Your e-mail address is never displayed. If you run into issues with SpamKarma blocking you, email me at $patrick->5etdemi(com)


RSS feed for comments on this post | TrackBack URI