Accessibility

Flash Article

 

Exploring the version 2 component architecture in Flash 8


Table of Contents

Comments

Understanding UIObject and UIComponent

UIObject and UIComponent base classes

UIObject and UIComponent are the base classes of the v2 component architecture. Both define methods and properties that all other components share, including a system for component creation. Understanding the principles at work in these two classes is important for building components.

UIObject (mx.core.UIObject)

UIObject directly subclasses MovieClip. By providing a wrapper around its methods and properties, it makes the syntax more intuitive and improves the conceptual management of representing graphic objects with movie clips.

A UIObject or UIObject subclass resizes itself by scaling. When you change its size using the size() method, the new dimensions are handed to the _width and _height movie clip properties, which scale the subclass.

The UIObject and UIObject subclasses broadcast their events just before drawing, analogous to the enterFrame() movie clip event. UIObject also defines the styling, skinning, and event aspects of the component architecture.

UIComponent (mx.core.UIComponent)

UIComponent is a subclass of UIObject. It defines high-level behaviors that are specific to a graphic object. UIComponent handles end-user interactions (clicking, dragging, focus, etc.) and component enabling and disabling. It also offers the draw() method, which you can override to customize how UIComponent handles calls to its size() method. UIComponent inherits all the methods, properties, and events of UIObject.

Considerations When Subclassing UIObject or UIComponent

Each component subclass defines methods that are specific to its task as a component, but there are a few methods that every component implements, which guarantee that the component takes advantage of system-level services provided by UIObject and UIComponent:

  • init() is called when the component is created. At the very least, a component's init() method should call the init() method of the superclass—for example, super.init(). Additionally, init() may set initial values for properties.
  • draw() is called when the component is invalidated, such as at initialization time. Components should implement the draw() method to make subObjects visible and perform the initial layout.
  • size() is called when setSize() is called on a component. Components should override this method to lay out subObjects every time the component's size changes.