Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Classes > About object-oriented programming and Flash > 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.
When you use a class, you can also extend existing classes and add new functionality or modify existing functionality. For example, if you create three very similar classes, you can write a base class and then write two other classes that extend the base class. These two classes can add additional methods and properties, so that you don't need to create three class files that all duplicate the same code and logic.
Another benefit of using classes is code reusability. For example, if you create a custom class that creates a custom progress bar using the Drawing application programming interface (API), you could save the progress bar class in your classpath and reuse the same code in all of your Flash documents by importing the custom class. For more information on setting the classpath, see About importing class files and About setting and modifying the classpath.
|
|
|
|