Home arrow Flash arrow Page 5 - Object-oriented ActionScript
FLASH

Object-oriented ActionScript


This chapter provides a high-level overview of object-oriented programming (OOP) in ActionScript for experienced programmers who are making their first foray into Flash development. (From the book Essential ActionScript 2.0, by Colin Moock, O'Reilly Media, ISBN:0596006527.)

Author Info:
By: O'Reilly Media
Rating: 4 stars4 stars4 stars4 stars4 stars / 15
August 30, 2004
TABLE OF CONTENTS:
  1. · Object-oriented ActionScript
  2. · Key Object-Oriented Programming Concepts
  3. · Object Creation and Usage
  4. · Encapsulation and Datatypes
  5. · Inheritance, Packages, Compilation
  6. · Starting an Objected-Oriented Application
  7. · An Example Website

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Object-oriented ActionScript - Inheritance, Packages, Compilation
(Page 5 of 7 )

When developing an object-oriented application, we can use inheritance to allow one class to adopt the method and property definitions of another. Using inheritance, we can structure an application hierarchically so that many classes can reuse the features of a single class. For example, specific Car, Boat, and Plane classes could reuse the features of a generic Vehicle class, thus reducing redundancy in the application. Less redundancy means less code to write and test. Furthermore, it makes code easier to change—for example, updating a movement algorithm in a single class is easier and less error prone than updating it across several classes.

A class that inherits properties and methods from another class is called a subclass. The class from which a subclass inherits properties and methods is called the sub-class’s superclass. Naturally, a subclass can define its own properties and methods in addition to those it inherits from its superclass. A single superclass can have more than one subclass, but a single subclass can have only one superclass (although it can also inherit from its superclass’s superclass, if any). We’ll cover inheritance in detail in Chapter 6.

Packages

In a large application, we can create packages to contain groups of classes. A package lets us organize classes into logical groups and prevents naming conflicts between classes. This is particularly useful when components and third-party class libraries are involved. For example, Flash MX 2004’s GUI components, including one named Button, reside in a package named mx.controls. The GUI component class named Button would be confused with Flash’s built-in Button class if it weren’t identified as part of the mx.controls package. Physically, packages are directories that are collections of class files (i.e., collections of .as files).

We’ll learn about preventing naming conflicts by referring to classes within a package, and much more, in Chapter 9.

Compilation

When an OOP application is exported as a Flash movie (i.e., a .swf file), each class is compiled; that is, the compiler attempts to convert each class from source code to bytecode—instructions that the Flash Player can understand and execute. If a class contains errors, compilation fails and the Flash compiler displays the errors in the Output panel in the Flash authoring tool. The error messages, such as the datatype mismatch error described earlier, should help you diagnose and solve the problem. Even if the movie compiles successfully, errors may still occur while a program is running; these are called runtime errors. We’ll learn about Player-generated runtime errors and program-generated runtime errors in Chapter 10.

Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

Visit the O'Reilly Network http://www.oreillynet.com for more online content.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials