Accessibility

Table of Contents

Exploring the version 2 component architecture in Flash 8

Examining the Component Architecture

Version 2 of the Flash 8 family of components provides a foundation for growth and expansion as users and Macromedia build onto it. Its hierarchy of classes (see Figure 1) comprise the UI components—which most Flash users are familiar with from the Components panel—and a number of other singleton classes, smaller hierarchies, and other resources that exist as various managers and mix-ins (see the section "Using Managers and Mix-ins") to provide system-level application services or to assist in component development.

Hierarchy of classes in Version 2 of the Flash 8 component architecture

Figure 1. Hierarchy of classes in Version 2 of the Flash 8 component architecture (click to open full-sized diagram)

This hierarchy is made possible because of inheritance—the concept by which a class inherits the methods and properties of another class by subclassing it. If you're familiar with the concept of inheritance, skip to the next section.

Inheritance

Here is the definition for the Label class (mx.controls.Label) that was made possible with the new class keyword:

class mx.controls.Label extends UIObject {
...
}
          

Note the right-hand side of this statement—in particular the keyword extends. This phrase sets up the inheritance chain by making the class UIObject the superclass of Label. At compile-time and runtime, any methods or properties not defined in Label will be looked for by the compiler in UIObject, and so on until you reach the first superclass. If a method or property is not found then, the compiler returns an error.

Label is but one example of inheritance at work. Inheritance facilitates the development of classes and objects that specialize in performing functional tasks for better code reuse. Understanding inheritance provides a basis for understanding and developing Macromedia MX components.

Find more information about inheritance in Using Components in Flash Help.

Events

The event model is a dispatcher/listener model based on the DOM Level 3 proposal for event architectures. Every component in the architecture emits events in a standard format, as defined by the convention. Those events vary across components, depending on the functionality the component provides.

Components leverage the EventDispatcher mix-in (mx.events.EventDispatcher) to maintain a list of listeners that receive events when they are broadcast.

An event listener can be any object or method that conforms to the prescribed syntax, which accepts an event object as a parameter. An event object is a loosely typed object containing specific properties that carry information about the event—including its type, target, and, optionally, relevant information about the state change the event's emission represents.

Upon receiving the event, the listener code uses this event information to determine the actions to perform. Here's an example of an event listener:

listenerObject.eventName = function(evtObj){
  // your code here
	this._x += 10;
};
componentInstance.addEventListener("eventName", listenerObject);
          

In this code, the keyword this, if used in the callback function, is scoped to the listenerObject.

While every component can define unique events, events are inherited along the prototype chain. The core classes of the architecture, mx.core.UIObject and mx.core.UIComponent, define low-level component events like draw, resize, move, load, and others that are fundamental to all components. Subclasses of these classes inherit and broadcast these events.

Find more information about events, handling syntaxes, and the mix-in classes that enable event broadcasting in Using Components in Flash Help.