
210
CHAPTER 11
The AlignmentManager can manage only objects that are MovieClips, so the header artwork has
been converted to a MovieClip and given an instance name of headerBackground_mc. With the
headerBackground_mc item selected in the MovieClip tree, you can specify values for
HorizontalAlignment,
VerticalAlignment, and Margins. After making changes, you have to click the save changes button (an
admitted quirk of the panel).
We’ve included an alternative version of the Draw Rect sample file that uses the AlignmentManager
to completely define the resize behavior of the panel. (See the version of Draw Rect.fla located in
the source projects folder as “Draw Rect/4. Using the Alignment Manager/Draw Rect.fla”.) The final
version behaves nicely as it is resized in Fireworks. Republish Draw Rect.fla to see the final layout
behavior in Fireworks as the panel is resized:
The background artwork stretches to fill the panel.
The header background stretches horizontally.
The logo remains anchored to the top- left corner.
Configuration fields remain anchored to the top- left corner.
The Add Rect button anchors to the lower- right corner.
Coding this resize behavior by hand would have taken a long time and be very frustrating to maintain.
Using this panel empowers you to deliver expected layout results in a fraction of the time you would
spend hand- coding the same behavior.
Responding to Fireworks events
Up to this point, we’ve been pretty much oblivious to what’s been going on around us in Fireworks.
We haven’t cared about selection changes or tool changes or documents opening or closing. We’ve
just focused our attention on one thing: creating rectangles. For content creation panels, this is fine,
but for panels that need to respond to selection changes (such as the
Gradient panel), we need a way
to react to such changes. Fireworks provides a number of events that we can listen for and handle
directly via ActionScript. We’ll show you how to handle these in ActionScript 2 (since we’ve been using
ActionScript 2 exclusively so far) and save the ActionScript 3 demonstration for the section “Building
panels with ActionScript 3” later in the chapter.
Detecting change of selection
Let’s start by handling the onFwActiveSelectionChange event. This event is raised any time you select
a different object on the Fireworks design surface. With the
Gradient panel, we handle this event and
redraw the brush preview based on the fill of the selected object. Fireworks event handling is a little
different from traditional event handling. In Fireworks, you simply define an ActionScript function
with the name of the event you wish you handle. When Fireworks checks for event handlers, it will
find your matching function name and register it. Any time the event is raised, your function will be
called.
The following ActionScript defines a function named onFwActiveSelectionChange. When the selec-
tion changes in Fireworks, an alert box is displayed.
Kommentare zu diesen Handbüchern