<classwork>

Flash ActionScript 2.0


ActionScript is the scripting language used by Macromedia Flash. There are two versions of ActionScript: ActionScript 1.0 and ActionScript 2.0.

ActionScript 1.0, the less formal version of ActionScript, is fine for most general purposes and when you want to target an old version of Flash Player. Want to generate some simple interactivity when a user clicks a button? Want to create an application for a mobile device? Go with ActionScript 1.0. But for creating more complex code, ActionScript 2.0 is more appropriate.

ActionScript 2.0 is an object-oriented programming language that supports full class inheritance and all the features that developers demand from a mature language.

The object-oriented programming (OOP) features in ActionScript 2.0 are based on the ECMAScript 4 Draft Proposal currently in development by ECMA TC39-TG1 for Javascript 2.0 (see www.mozilla.org/js/language/es4/index.html). Because the ECMA-4 proposal is not yet a standard, and because it is still changing, ActionScript 2.0 is loosely based on this specification.

ActionScript 2.0 supports all the standard elements of the ActionScript language; it lets you write scripts that more closely adhere to standards used in other object-oriented languages, such as Java. ActionScript 2.0 should be of interest primarily to intermediate or advanced Flash developers who are building applications that require the implementation of classes and subclasses. ActionScript 2.0 also lets you declare the object type of a variable when you create it (var x = 3; instead of x=3; see variables for more info.) and provides significantly improved compiler errors (error messages).


With ActionScript 2.0, you can create custom classes and extend built-in classes of Flash.

Compiler warnings and errors: The two features (OOP model and strict data typing) enable the authoring tool and compiler to provide compiler warnings and error messages that help you find bugs in your applications faster than was previously possible in Flash.


Key facts about ActionScript 2.0 include the following points:

  • Scripts that use ActionScript 2.0 to define classes or interfaces must be stored as external script files (.as), with a single class defined in each script; that is, classes and interfaces cannot be defined in the Actions panel.
  • You can import individual class files implicitly (by storing them in a location specified by global or document-specific search paths and then using them in a script) or explicitly (by using the import command); you can import packages (collections of class files in a directory).
  • Applications developed with ActionScript 2.0 are supported by Flash Player 6 and later.

    CAUTION
    The default publish setting for new files created in Flash 8 is ActionScript 2.0. If you plan to modify an existing FLA file with ActionScript 1.0 to use ActionScript 2.0 syntax, ensure that the FLA file specifies ActionScript 2.0 in its publish settings. If it does not, your file will compile incorrectly, although Flash will not necessarily generate compiler errors.


  • Migrating to ActionScript 2.0

    The first thing to understand about updating ActionScript 1.0 code to ActionScript 2.0 code is that, in many cases, it's not necessary. ActionScript you wrote in earlier versions of Flash continues to work in Flash.

    Migrating your code from ActionScript 1.0 to ActionScript 2.0 is beneficial mainly in the following circumstances:

  • For a large-scale Flash application or presentation that contains a lot of code, using ActionScript 2.0 simplifies the development process and provides more debugging information than ActionScript 1.0.
  • To upgrade OOP programs that you created originally in Flash MX or Flash 5, using ActionScript 2.0 makes maintaining and modifying the code much easier.

    Also remember that you do not need to write class files in order to leverage some of the benefits or capabilities of ActionScript 2.0 or V2 components. You can still write ActionScript 2.0 code (such as code that applies data type annotations to variables) using frame scripts on a timeline.


  • Understanding ActionScript and Flash Player

    There are distinctions between Flash Player and ActionScript versions that can be very important to understand when building Flash applications.

    You can compile a Flash document using ActionScript 1.0 or ActionScript 2.0 to Flash Player 6, 7, or 8, and it will work correctly. That is because both ActionScript 1.0 and ActionScript 2.0 compile to the same bytecode (the code that the ActionScript interpreter in Flash Player reads.) However, there are new ActionScript APIs (functions, classes, properties, and methods) introduced in each new version of Flash Player.

    API defined:
    Abbreviation of application program interface, a set of routines, protocols, and tools for building software applications. A good API makes it easier to develop a program by providing all the building blocks. A programmer puts the blocks together.

    For example, the loadMovie() method of the MovieClip class works in Flash Player 6, 7, and 8. However, the MovieClipLoader class works only in Flash Player 7 and 8. That means that even though you can use either ActionScript 1.0 or ActionScript 2.0 for any of those player versions, you have to be careful that the APIs you use are supported in the target player version.

    Neither ActionScript 1.0 nor ActionScript 2.0 are case-sensitive. However, Flash Player 7 and Flash Player 8 are case-sensitive. That means that regardless of whether or not you use ActionScript 1.0 or 2.0 the variables userName and UserName are the same in Flash Player 6, but they are different variables in Flash Players 7 and 8.