ActionScript 2.0 introduces several programming keywords and concepts, including classes, inheritance, and interfaces. These concepts comprise what is commonly known as object-oriented programming. See the following sections of Flash LiveDocs for more information:
Features of ActionScript 2.0 include the following:
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 = “Fred”;
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 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 no errors will be generated.
Classes you create in ActionScript must be stored in separate ActionScript (AS) files; you can't create classes in a frame on a timeline (frame script), or attach one to a movie clip or button instance. Some important points about class files:
For more information on classes and object-oriented programming, read the Object-Oriented Programming section of this guide. If you're new to creating classes and object-oriented programming, try the steps in the following section of Flash LiveDocs: Learning ActionScript 2.0 > Classes > Example: Writing Custom Classes.
For more information, see the following sections of Flash LiveDocs:
When you start a new document or application in Flash, you must decide how to organize its associated files. You might use classes in some projects, such as when you are building complex applications, but not all documents use classes. For example, many short examples in the Flash documentation do not use classes.
Using classes to store functionality is not the easiest or best solution for small applications or simple FLA files. When you build a small project, it is often more work and effort to use classes or external code files to organize ActionScript instead of adding ActionScript within the FLA file. It is often more efficient to put ActionScript inside the document. In this case, try to put all your code on the Timeline on as few frames as possible, and avoid placing code on or in instances (such as buttons or movie clips) in a FLA file.
If you decide to keep all the ActionScript code within the FLA file, rather than placing it within a class that you import, this does not mean that you should necessarily use ActionScript 1.0. You might decide to put your code inside the FLA document and still opt to use ActionScript 2.0 with its strict data typing and its new methods and properties. ActionScript 2.0 also offers a syntax that follows standards in other programming languages. This makes the language easier and more valuable to learn. For example, you will feel familiar with ActionScript if you have encountered another language that's based on the same structure and syntax standards. Or, you can apply this knowledge to other languages you learn in the future. ActionScript 2.0 lets you use an object-oriented approach to developing applications by using an additional set of language elements, which can be advantageous to your application development.
In some cases, you cannot choose which version of ActionScript to use. If you are building a SWF file that targets an old version of Flash Player, such as a mobile device application, you must use ActionScript 1.0, which is compatible with Flash Player for a number of devices.
Remember, regardless of the version of ActionScript, you should follow good practices. Many of these practices, such as remaining consistent with case sensitivity, using code completion, enhancing readability, avoiding keywords for instance names, and keeping a consistent naming convention, apply to both versions. If you plan to update your application in future versions of Flash, or make it larger and more complex, you should use ActionScript 2.0, classes, and version control, to make it easier to update and modify your application. For more information on class files, see the Object-Oriented Programming section.
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 8 and Flash Player 8.
Migrating your code from ActionScript 1.0 to ActionScript 2.0 is beneficial mainly in the following circumstances:
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.
Although new versions of ActionScript and Flash Player are often released simultaneously, they are not always synonymous. 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. 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.