In order to make the root movieclip a subclass of some ActionScript 3.0 class you wrote, there are a few steps to follow.

  • The AS3 class must extend MC or Sprite class, because the root object of a Flash file is based on these:
    public class SomeClass extends MovieClip
  • The package name (the first line of the class file) must match the directory you are in — relative to the FLA file (not the SWF output file). So if your FLA file is kept in the directory:
    c:Flash

    and your AS3 class is kept in the file:

    c:FlashAS3SomeClassPackageSomeClass.as

    you must list the package in your class (on the first line of your file) as:
    package AS3.SomeClassPackage

  • A reference to the package and class must be in your root object’s Class box:
    Where to add superclass info on a Flash root object

    Where to add superclass info on a Flash root object

    You will be prompted if you do not enter it correctly. Just cut-and-paste the package listed in your class file, and then cut-and-paste the class name:
    AS3.SomeClassPackage.SomeClass

    Save it and test it before you do any serious coding. The trick I use is putting a trace in the class constructor, and I run a debug (“Debug | Debug Movie”) on the Flash file. If it is working, I will see the results in the “Output” window (“Window | Output”), and not if it is not:

    public function SomeClass()
    {
    trace("SomeClass - working!");
    }

    (If you do this, make sure that in “File | Publish Settings . . .” on the Flash tab, in the advanced settings, “Omit trace actions” is unchecked, and “Permit debugging” is checked.)

  • – 30 –

    Advertisements