About object-oriented programming and Flash
227
Flash Player 8, available in both Flash Basic 8 and Flash Professional 8, adds several new
features to the ActionScript language such as filter effects, file upload and download, and the
External API. As always, ActionScript 2.0 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 Basic 8 and Flash Professional 8 include 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”
on page 250
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:
■
“The benefits of using classes” on page 227
■
“About packages” on page 228
■
“About values and data types” on page 231
■
“Object-oriented programming fundamentals” on page 231
The benefits of using classes
In OOP, a class defines a category of object. A class describes the properties (data) and
methods (behaviors) for an object, much like an architectural blueprint describes the
characteristics of a building. You write a custom class in an external ActionScript (AS) file and
you can import it into your application when you compile the FLA file.
Classes can be very useful when you build larger Flash applications because you can organize a
lot of the application’s complexity in external class files. When you move a lot of the logic into
a custom class, you can not only make the code easier to reuse, but you can also “hide” some
of the methods and properties from other parts of the ActionScript code. This helps you
prevent people from accessing sensitive information or changing data that shouldn’t
be changed.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...