The Class Hierarchy of Built-In Objects

 <  Day Day Up  >  

In Flash, there is a built-in object hierarchy that is used even without creating a single superclass or subclass. Each time you use a built-in object in Flash, you are using the object hierarchy.

Everything Is an Object

In Flash, everything is derived from the Object class. The Object class provides a set of methods that are useful to all objects, visual and nonvisual. Table 5.1 shows the methods in the Object class definition.

Table 5.1. Object Methods (from Flash Help Files)




Creates a getter/setter property on an object


Associates a movie clip symbol with an ActionScript 2.0 object class


Converts the specified object to a string and returns it


Removes the watchpoint that created


Returns the primitive value of an object

Registers an event handler to be invoked when a specified property of an ActionScript 2.0 object changes

Because every object in Flash inherits from the Object class, they all have the Object methods available. Of particular interest is the Object.registerClass() method. This method allows us to create a link or relationship between a visual Library entry and an object definition.

Visual and Nonvisual Objects

In ActionScript 2.0, as in other languages, we can classify our objects as visual or nonvisual. This is an important distinction and should be determined during the design phase of an application. There are many design patterns that strictly delineate between visual and nonvisual entities in a pattern. Chapter 8, "Object-Oriented Design," provides examples of design patterns.

We can also use this distinction for application partitioning. Classic partitioning uses a client/server model, where the client represents the visual or display components and the server represents the nonvisual or data components . In Flash, the MovieClip object is the most commonly used visual object. Nonvisual objects are created as classes to encapsulate data and business logic. Implicitly both the MovieClip object and all nonvisual classes share a common ancestor in Flash ”the Object object.

For example, in our loan application, loanCalc.fla is the client or visual component and Loan.class is the nonvisual data component serving data to the client. See Figure 5.2.

Figure 5.2. Loan hierarchy.


Where Do Our Classes Fit In?

As we start to create objects in an application, we categorize them as visual and nonvisual. After we have made the delineation between the two, we can use built-in Flash objects to get us started. All nonvisual objects implicitly inherit the properties of the Object class. Visual objects can inherit from the MovieClip class or any other class derived form the MovieClip class.

 <  Day Day Up  >  

Object-Oriented Programming with ActionScript 2.0
Object-Oriented Programming with ActionScript 2.0
ISBN: 0735713804
EAN: 2147483647
Year: 2004
Pages: 162 © 2008-2017.
If you may any questions please contact us: