Migrating from ActionScript 2 to ActionScript 3 Notes

Migrating from ActionScript 2 to ActionScript 3 Notes

I have been attempting to updated an old Flash CS4 project written in AS2 to the current version of Flash Pro CC, and discovered that it no longer supports AS2. So, you are forced to update your project.

Conversion Strips Scripts

The update process strips out any scripts attached to the instances, which I guess is good. I don’t think I was using any. You don’t get any kind of list telling you that there’s a problem.

New Package Usage Syntax

All my scripts are organized by folder in the dseah package hierarchy, and there are subpackages like dseah.ett and dseah.io. I’m working through compiler errors about packages; notably:

5007: An ActionsScript file must have at least one externally visible definition.

Googling this error brings up advice in wrapping this in a package so you can declare the constructor of your class public. Here’s an example of an old AS2 class:

import mx.services.*;
import dseah.io.Debugger;

class dseah.io.DSWebService {
    function DSWebService(wsdl:String, listener:Object, func:Function) {

Most of the blathering on StackExchange suggests wrapping everything in a the global package, as in:

package {
    import mx.services.*;
    import dseah.io.Debugger;

    class dseah.io.DSWebService {

You will, however, get a NEW error:

1037: Packages cannot be nested.

It took me a while to figure out what this meant, because there is a lot of blather on StackExchange about “autogenerated package namespaces” and “try purging your project cache in FlexBuilder” and even “It works for me.” It actually is another change in AS3 from AS2, and it’s a big DUH: when using the package keyword, you must match the hierarchy and the class names no longer have the path. This is the way other languages work, and it makes sense. It should look like this:

package dseah.io {
    import mx.services.*;
    import dseah.io.Debugger;

    class DSWebService {

Then, the error goes away.

Need to explicitly include packages

The built-in Flash classes now have to be explicitly imported.

Changes in Focus and Events

Selection goes away, and is accessible now as the stage.focus property of a DisplayObject (movieclip, textfield).

TextField.onKillFocus and onSetFocus are replaced with general event listener syntax: addEventListener(FocusEvent.FOCUS_OUT, function (e:Event) { ... });

Changes to SOAP

It’s gone, and has been replaced with something new.

setInterval() and getTimer() changes

The callback works differently, accepting now a function reference instead of a closure object + function name string.

Loss of _root

There’s no easy way to grab _root. Working on fix.

Loss of TextFormat.getTextExtents()

Workaround is to make a new TextField, set its text format and text, and pull its textWidth and textHeight properties afterwards. This is possible now that the TextField isn’t a weird Flash object.


… work ongoing to get to an error-free compile, then to see what else has broken. Sigh.

1 Comment

  1. Amanda 9 years ago

    Thanks for the post!

    I had the same error messages, first 5007 and then 1037. Now that I tried to fix the issue, I get a 1084 syntax error: expecting identifier before as. Now that if I remove the file type ‘.as’ text from that line, I get back to error code 1037: packages can not be nested. The error line looks like this now: class caurina.transitions.Tweener { And the document beginning looks like this: package caurina.transitions { import caurina.transitions.Equations; import caurina.transitions.AuxFunctions; import caurina.transitions.SpecialProperty; import caurina.transitions.SpecialPropertyModifier; import caurina.transitions.SpecialPropertySplitter; import caurina.transitions.TweenListObj; import caurina.transitions.PropertyInfoObj;

    class caurina.transitions.Tweener {
        private static var _engineExists: Boolean = false; // Whether or not the engine is currently running
        private static var _inited: Boolean = false; // Whether or not the class has been initiated
        private static var _currentTime: Number; // The current time. This is generic for all tweenings for a "time grid" based update
        private static var _currentTimeFrame: Number; // The current frame. Used on frame-based tweenings
        private static var _tweenList: Array; // List of active tweens
        private static var _timeScale: Number = 1; // Time scale (default = 1)
        private static var _transitionList: Object; // List of "pre-fetched" transition functions
        private static var _specialPropertyList: Object; // List of special properties
        private static var _specialPropertyModifierList: Object; // List of special property modifiers
        private static var _specialPropertySplitterList: Object; // List of special property splitters
        public static var autoOverwrite: Boolean = true; // If true, auto overwrite on new tweens is on unless declared as false
         * There's no constructor.
        public function Tweener() {
            trace("Tweener is an static class and should not be instantiated.");

    If I add at the beginning line ‘.Tweener’ or ‘Tweener.as’, the line is like this: package caurina.transitions.Tweener.as { and I still get the same 1037 error, and if with the ‘.as’ extension, I get both 1037 and 1084 error codes.

    I’m stuck here. I had googled on those error codes, and for someone the solution was to change some of the instance names, because they had been the same as some keywords, due to capital letter at the beginning.

    I guess I will check my instance names and see if there is any error with them.