At some point, you may want to build advanced components. For instance, you may want to create a truly custom component or a commercial-grade distributed component, or you may just want a much deeper understanding of and level of control over the underlying framework. Although Flex allows you to build components rapidly, as we saw in Chapter 9, developing advanced components requires a deeper understanding of the component framework and methodology.
In this chapter, you will learn about the component framework life cycle and will develop an understanding of what it has to offer. You will do so through theory as well as by developing a custom component. You will also learn about ways to implement functionality within the component framework.
Understanding what the component framework implements, as well as how and where it does so, is key to building good components. Flex contains a sophisticated framework that aims to abstract many of the underlying details of Flash Player and add many features not supported natively by Flash Player. A majority of the framework is built to support a rich set of features for the UI components that the Flex components use. This framework allows components to share a common set of APIs, and it allows components to function in a predictable manner based on the needs of the Flex framework. Using this framework will allow you to develop your own custom components that also behave and operate in a consistent manner with other Flex components.
As with developing components for any platform, it is important to do some initial planning. This book doesn’t cover the theories and methodologies of designing components, but it is important to note that when developing custom components, it is highly recommended that you define requirements and the public interface and that you plan things more carefully before writing any code. This is not as important with application components (discussed in Chapter 9), but it is critical when developing custom components that others will consume. Also keep in mind that when developing custom components, there is always a chance that a user may extend your component.
The Flex component framework contains many classes, most of which we
won’t be covering in detail here. Instead, we will focus on the most
important classes for developing custom components: the UIComponent
and Container
classes. Figure 19-1 shows those classes and their
inheritance chain.
All interface components in Flex inherit from UIComponent
, which itself inherits from many classes, including Sprite
. When developing a custom component, you
will have to decide which of the following two classes to use: the
UIComponent
class or the Container
class. Generally speaking, you will use the UIComponent
class unless you are developing your
own container (e.g., if you need scrolling and clipping support built in).
The UIComponent
class is essentially an
abstract class that implements the core functionality the Flex framework
requires from components. It also implements most of the common sets of
behaviors, leaving you to implement the parts that are pertinent to your
component.
You could also use an existing component as the base class. In such a case, you would be extending the existing component rather than developing a completely custom component. We will not cover the specifics of how to extend components in this chapter, but many of the lessons you will learn in this chapter apply to extending components as well.
UIComponent
has several
requirements that you will need to understand; we will cover those
requirements later in the chapter. For now, it’s important to note that
UIComponent
implements what your
component needs in order to participate in the Flex framework and behave
appropriately. It also provides you with a predefined component life
cycle, as well as event handling, sizing, skinning, styling, invalidation,
and rendering techniques.