moock.org is supported in part by


August 17, 2007

migrating unity from ActionScript 2.0 to ActionScript 3.0

recently I finished migrating the code base for unity from ActionScript 2.0 to ActionScript 3.0. as I did the migration, I wrote down all the things I changed along the way. a few general trends I noticed:

-the code base got smaller (was 10000 lines, now 7000 lines)
-the code is much easier to follow
-Flex Builder's error messages guided me through most of the required changes

admittedly, I did a fair amount of refactoring, and that helped the code base's size and readability, but I was still pleasantly surprised to see that ActionScript 3.0 is generally not more verbose than ActionScript 2.0. in particular, all my xml handling is *much* shorter now, thanks to e4x.

here is the list of specific changes i made during the migration:

##
added package declaration for all classes

##
removed package name in class declarations

##
added 'public' modifier to class definitions

##
changed Void to void for all functions with no return value

##
removed access-control modifier (public) from interface members

##
changed private constructors to public

##
moved from custom depth management system to display api depth management (e.g.,
DisplayObject.addChild())

##
changed "private" to "protected" where subclasses need access to a member

##
explicitly declared "rest" parameter for methods that use undeclared (extra) parameters

##
changed undefined to NaN in checks for unassigned variables of type Number

##
imported flash.utils.* before using setInteral()/clearInterval()

##
added default values for optional parameters (e.g., port:int = 9100)

##
removed member access through variables whose value is null. e.g.,
var o = null;
o.m() // Error in ActionScript 3.0, allowed in ActionScript 2.0

##
added thrown exceptions for error conditions

##
changed Number to int where appropriate

##
changed System.security to flash.system.Security

##
changed legacy XML objects to E4X XML objects

##
changed system.capabilities to system.Capabilities

##
removed check for XMLSocket.connect() return value (no longer returns a boolean).
listen for securityError instead.

##
imported SharedObject from its new package (flash.net)

##
added "override" attribute to method overrides

##
changed XML.load call to URLLoader

##
changed "typeof" datatype checks to "is"

##
changed fixed-value variables to constants

Posted by moock at August 17, 2007 10:03 PM