as3converter
Summary
- Homepage : http://www.spikefin.org/downloads
- License : GPL2
AS3 Converter is an ant task (or two) and a small collection of AS3 classes to aid porting an ActionScript2 project to ActionScript3.
We need to keep developing our main product in AS2, and will be for some time, however, I really want to port it. A code fork seemed too difficult, so a converter and an api compatibility layer that lets us develop them in tandem seemed the answer. I am having some success with it, and have had some working bits and pieces going.
It works by parsing an ActionScript2 source tree in to an in memory model of the source, then outputs it in ActionScript3 syntax, as well as applying some other conversions to make the code compile.
- Rewrites AS2 classes in AS3 syntax
- Automatic ‘override’ inserting
- use @scope javadoc tag to change output function scope
- use @default to insert parameter defaults in to output function
- ability to specify AS3 equivalent classes, such as MovieClip → as2.toplevel.MovieClip, or org.chaps.MyStringLibrary → org.chaps.utils.MyStringLibrary.
- ‘Void’ to ‘void’
- Small collection of compatibility classes to provide api compatibility
- MovieClip
- TextField
- Stage
- Mouse
- ...
- Ant task that uses swfmill to create an AS3 asset library class using an existing swf.
In the works
- Swaps comparisons of Number to null for isNaN tests. I got very bored doing this by hand, so have decided to implement this. It meant a complete rewrite of large chunks of the code, but it has been quicker and has resulted in quite a performance increase.
- Methods default to having ...as2args argument appended to their signature unless instructed not to, or if this method is overriding a method which doesn’t have the ...as2args.
- Function parameters automatically have defaults, except when instructed not to.
Now, if only someone could write an algorithm to remove all of my ReferenceErrors...
Tutorials
Download the example project at www.spikefin.org, and extract it somewhere. This will give you an idea of how the most basic project works, and is a good platform for seeing what you can and can’t do with the converter.
Run the example using the default target of the included build script.
Javadoc style directives
Besides the basic syntax changing, you can give the converter some extra instructions. These are declared using javadoc style properties, like @directive [param[=value]].
Class Directives
@convert true/false Tell the converter to skip this class
@equivalent className Tell the converter to use className as a substitute for this class.
In development
@strictArguments true/false Tell the converter not to add defaults to function parameters and var args to output code.
Method Directives
@default paramName=defaultValue Allows you to specify parameter defaults in the output methods signature.
@scope outputScope Specify the scope of the output method.
Demos
Download a sample project from Here
Download
Get it from the home page.
Discussion
projects/as3converter.txt · Last modified: 2007/06/08 23:09 by nicobrevin