What Is a Flash MX Component?by Colin Moock, author of ActionScript for Flash MX: The Definitive Guide, 2nd Edition
Last March Macromedia released Flash MX with a compelling new vision for the product: the animation and design software would henceforth be groomed as a rich Internet application platform. Accordingly, some heavy changes were made to the authoring environment. Macromedia added an extensible library of user interface widgets, known as the Flash UI Components, for quickly creating common GUI applications. (Previously, Flash developers were expected to bake all UI in their own ovens.) Java developers accustomed to working with Swing or Visual Basic developers used to a drag-and-drop environment will appreciate this critical step in the direction of rich application development for the Web.
Flash UI Components are actually a specific example of the more general Flash MX component architecture. A component in Flash MX is a reusable, packaged module that adds a particular capability to a Flash movie. Components can include graphics as well as code (as do the built-in Flash UI Components), so they're neat little bundles of self-contained functionality that you can easily drop into your projects. For example, a component can be a radio button, a dialog box, a preload bar, or even something that has no graphics at all, such as a timer, a server connection utility, or a custom XML parser.
From a technical point of view, a component is Flash MX's version of Flash 5's smart clip, which is a movie-clip symbol that allows its variables (or "clip parameters") to be set via a GUI in the authoring tool. Flash MX components are typically subclasses of the built-in MovieClip class, but they're not required to be. As such, they have all the properties and methods of MovieClip, plus their own properties and methods. (For the uninitiated, a MovieClip is Flash's basic content container, something like a DHTML layer in a web page.)
So the answer to "what is a Flash MX component?" depends partly on your point of view. From a traditional Flash point of view, components are effectively ready-made movie clips that you install and drag into your movies. From a programmer's point of view, components are customizable building blocks that can be added to an application visually or programatically and then wired into the application's logic and data.
Flash MX components are Macromedia's effort to provide visual programmers with a drag-and-drop development environment, much like Microsoft Visual Basic. Using components you can create a user interface visually in the Flash authoring tool and then easily hook that interface up to routines that perform some action. Figure 1 is a screenshot showing the creation of a fill-in form with checkbox, listbox, and pushbutton components.
Figure 1. A fill-in form with checkbox, listbox, and pushbutton components.
The component architecture is fully extensible. If you're an advanced Flash developer, you can create your own components and distribute them as binary files for other Flash developers to install. The extensible component architecture allows Macromedia to update the capabilities of Flash MX by shipping new component sets, without requiring an updated version of the core authoring tool. Some developers also use components to distribute code-only libraries such as basic game classes or data-handling utilities. While the use of components for code distribution is common practice, the jury is still out on whether it is the best practice. Flash MX does not impose a strict policy on code distribution. Code can be distributed in a component, in a .as file included in other .fla files, in a runtime or author-time shared library, or in a .swf file that is dynamically loaded at runtime. The distribution method you choose will depend on your situation.
Chapter 14, "Movie Clip Subclasses and Components" and Chapter 16, "ActionScript Authoring Environment," of ActionScript for Flash MX: The Definitive Guide describe how to create components and explain how components work under the hood. You can also check out Macromedia's online technotes:
How to Build a Flash MX Component (shows how to subclass MovieClip)
Creating Components (explains how to make a basic component without subclassing MovieClip)
Of course, the best way to learn about components is to try them out. The following sites all have plenty of components free for download:
You'll need the "Extension Manager" to install components (which are distributed as .mxp files). You can get the Extension Manager at the Macromedia Flash Exchange.
Here are resources to learn how to use components to create a GUI application:
Introduction to Components Tutorial
In the Flash MX authoring tool, select Help > Tutorials > Introduction to Components
In the Flash MX authoring tool, select Help > Using Flash > Using Components
Building an Address Book with Components (by Colin Moock)
Creating Forms with Components in Macromedia Flash MX
Colin Moock is an independent Flash platform expert with a passion for networked creativity and expression. He has been researching, designing, and developing for the Web since 1995.
O'Reilly & Associates recently released (January 2003) ActionScript for Flash MX: The Definitive Guide, 2nd Edition.
Sample Chapter 13, Movie Clips, is available free online.
For more information, or to order the book, click here.
Return to the Web Development DevCenter.
Copyright © 2009 O'Reilly Media, Inc.