Hack 73 Optimize Component Downloading and Usage 
Flash ships with a large number of components,
which are a useful solution to common Flash design tasks. Minimize
the considerable download delay they can cause at the start of your
SWF.
Many Flash
presentations, especially business applications or movies meant to
simulate desktop applications, require standard UI elements such as
buttons and drop-down lists. These standard elements are provided by
Macromedia in the form of prebuilt components, as shown in Figure 9-11.

Components are a
special type of movie clip that can be used as the building blocks of
common UI elements or provide ActionScript classes to aid in the
building of advanced interactivity or communication between Flash and
other web technologies.
When you compile the FLA into a SWF, Flash scans through the timeline
and makes a list of all the assets and the order in which they
appear. It then adds the assets to the SWF in that order, so
streaming can occur efficiently. If an asset never appears on the
timeline, it never gets added to the list and therefore never gets
exported, thus keeping the SWF filesize to a minimum.
That optimization works well, except when you use an asset or
component via ActionScript but not in the timeline. You can force
Flash to include assets even if they are not used in the timeline by
selecting the Export for ActionScript checkbox in the Linkage
Properties dialog box. Components have this option checked by
default, so they are included in the SWF even if they
aren't used in the timeline. If you place components
on Stage (which adds them to the Library) and then later delete them
from the Stage, they remain in the Library. This is the preferred way
to add needed components to the Library. However, be sure to delete
unused components from the Library (or uncheck their Export for
ActionScript checkboxes) or they'll be included in
the SWF even if you don't use them via the timeline
or ActionScript.
Flash MX
2004 components (also known as v2 components)
are a major redesign of the original Flash MX v1 components, but they
require an initial download of around 25-30 KB, which occurs by
default in the first frame of your SWF. The resultant delay for
low-bandwidth users can be off-putting.
You can't avoid the download delay, but you can
change when it occurs. Under File Publish
Settings Flash, specify ActionScript 2.0 for the
ActionScript Version (the v2 components are written in ActionScript
2.0). Click the Settings button next to the ActionScript Version
drop-down list (Settings becomes selectable when you choose
ActionScript 2.0). When the ActionScript Settings dialog box appears,
in the Export Frame for Classes text
entry box, change the value to 2.
This setting forces Flash to export the component classes after frame
1 instead of before frame 1, allowing you to at least put something
up in the browser as the classes load. This is useful if you want to
create sites that work on low-bandwidth connections and use Flash MX
2004 components.
You shouldn't try to use any components until after
their classes have loaded (including the Preloader component). If you
want to use the Preloader component, you should add a dummy static
graphic that looks like the preloader showing 0%
on frame 1 and start animating it at frame 2.
Although the Flash MX 2004 components require a 30 KB
preload before they start working, this figure
doesn't increase measurably if you use more than one
component. That is, the v2 component architecture is optimized for
cases in which you use five or more components. The components are
also skinnable, allowing you to create a more customized look. And
they offer features like focus management and accessibility support.
If using a single component, especially if you don't
need the new features, it probably isn't worth using
the v2 components. Flash Player 7-compatible versions of the
v1 components, which are not as
bandwidth-heavy as the v2 components, are available from the
Flash
Exchange (http://www.macromedia.com/exchange/flash), in
the User Interface category, under the title Flash MX
Components for Flash MX 2004.
Some of the v1 components that come with Flash MX are not written
with case-sensitivity in mind, so they cause compiler errors when you
attempt to export them to Flash Player 7 format from Flash MX 2004,
regardless of whether you're compiling them as
ActionScript 1.0 or 2.0. The updated versions are case-sensitivity
compliant, so they will work in Flash MX 2004 for any combination of
ActionScript 1.0 or 2.0 and Flash Player 6 or 7 format export.
Many different component sets are available at the Flash Exchange.
Also worth considering is the
Macromedia Pocket PC
CDK (Content Development Kit), available at http://www.macromedia.com/devnet/devices. The
Pocket PC components that form a part of this kit are optimized for
low filesize and work for the desktop-based Flash Player (they work
for Flash Player 6 and appear to work well for Flash Player 7 when
using ActionScript 2.0 export settings).
If you require very limited functionality, you should consider
creating your own
components.
Most basic site designs require nothing more than a button and a
scrollbar, both of which can be created via a couple of 1 KB movie
clips. See also http://www.flashcomponents.com and
http://www.flashcomponents.net
for alternative components created by the Flash community, some of
which are designed with low filesize in mind.
Final Thoughts
Although v2 components ship with Flash MX 2004, they are certainly
not the only components you can use. The v2 components are geared
toward higher-bandwidth web applications. For general design, you can
use the Flash MX v1 components or even other Macromedia or
third-party components, such as those designed for the Pocket
PC.
|