About object-oriented programming and Flash

ActionScript 2.0 is an object-oriented language. Like ActionScript, OOP languages are based on the concept of classes and instances. A class defines all of the properties that distinguish a series of objects. For example, a User class represents a bunch of users who are using your application. Then, you have an instantiation of the class, which, for the User class, is one of the individual users--one of its members. The instantiation produces an instance of the User class, and that instance has all of the properties of the User class.

Classes are also considered like data types or templates that you can create to define a new type of object. For example, if you need a data type of Lettuce in your application, you might write the Lettuce class. This defines the Lettuce object, and then you can assign your Lettuce methods (wash()) and properties (leafy or bugs). To define a class, you use the class keyword in an external script file. You can create an external script file in the Flash authoring tool by selecting File > New and then selecting ActionScript File.

ActionScript 2.0 includes features such as filter effects, file upload and download, and the External API, and also provides several powerful and familiar OOP concepts and keywords (such as class, interface, and package) found in other programming languages, such as Java. The programming language lets you build program structures that are reusable, scalable, robust, and maintainable. It can also decrease development time by providing users with thorough coding assistance and debugging information. You can use ActionScript 2.0 to create objects and establish inheritance and to create custom classes and extend the Flash top-level and built-in classes. You learn how to create classes and use custom classes in this chapter.

Flash includes approximately 65 top-level and built-in classes that provide everything from basic, or "primitive," data types (Array, Boolean, Date, and so on), to custom errors and events, as well as several ways to load external content (XML, images, raw binary data, and more). You can also write your own custom classes and integrate them into your Flash documents or even extend the top-level classes and add your own functionality or modify existing functionality. For example, About class members in this chapter shows you how to make a custom Person class that contains custom properties for the person's name and age. You can then treat this custom class as a new data type in your documents and create a new instance of the class using the new operator.

For more information on working with OOP, see the following topics:


Flash CS3