Home / Articles / Adobe Flash / A Beginner's Look At ActionScript

A Beginner's Look At ActionScript

Chapter Description

ActionScript 2.0 offers new features unavailable in the previous version. This chapter explains what ActionScript is, and how 2.0 allows for greater customization of behaviors and scripts for Macromedia Flash animations.

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 (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 (see “About assigning data types and strict data typing” on page 83) and provides significantly improved compiler errors (see Appendix A, “Error Messages,” on page 787).

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, 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) by using wildcards.
  • Applications developed with ActionScript 2.0 are supported by Flash Player 6 and later.

For more information on using ActionScript 2.0 to write object-oriented programs in Flash, see Chapter 7, “Classes,” on page 231.

Although Macromedia recommends that you use ActionScript 2.0, you can continue to use ActionScript 1.0 syntax, especially if you are doing more traditional Flash work such as simple animation that doesn’t require user interaction.

What is ActionScript

The main features of ActionScript 2.0 include the following:

Familiar object-oriented programming (OOP) model The primary feature of ActionScript 2.0 is a familiar model for creating object-oriented programs. ActionScript 2.0 implements several object-oriented concepts and keywords such as class, interface, and packages that will be familiar to you if you’ve programmed with Java.

The OOP model provided by ActionScript 2.0 is a “syntactic formalization” of the prototype chaining method used in previous versions of Macromedia Flash to create objects and establish inheritance. With ActionScript 2.0, you can create custom classes and extend Flash’s built-in classes.

Strict data typing ActionScript 2.0 also lets you explicitly specify data types for variables, function parameters, and function return types. For example, the following code declares a variable named userName of type String (a built-in ActionScript data type, or class).

var userName:String = "";

Compiler warnings and errors The previous 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.

When you use ActionScript 2.0, make sure that the publish settings for the FLA file specify ActionScript 2.0. This is the default for files created in Flash MX 2004 and Flash 8. However, if you open an older FLA file that uses ActionScript 1.0 and begin rewriting it in ActionScript 2.0, change the publish settings of the FLA file to ActionScript 2.0. If you don’t, your FLA file will not compile correctly, and errors won’t be generated.

2. About choosing between ActionScript 1.0 and ActionScript 2.0 | Next Section