
211
EXTENDING FIREWORKS: DEVELOPING AN EFFECTIVE WORKFLOW USING JAVASCRIPT AND FLASH
function onFwActiveSelectionChange()
{
MMExecute("alert('Selection Changed!');");
// Do something with the selected object, like retrieve its color
// var currentColor:String;
// currentColor = MMExecute("fw.selection[0].pathAttributes➥
.fillColor");
}
This function needs to be defined at the _global level, meaning you should define these
event handlers either on the
Actions layer or in an #include ActionScript file. Defining
event handlers on nested MovieClips will render them useless.
Detecting tool changes
When the active tool changes in Fireworks (from the Pointer to the Text tool, for example), the
onFwActiveToolChange event is raised. Because no arguments are passed with this event, you have to
define a variable named fwActiveToolForSWFs in order to access the name of the active tool. Once this
variable is defined, Fireworks will update its value with the name of the currently active tool. The fol-
lowing ActionScript defines the fwActiveToolForSWFs variable and handles the onFwActiveToolChange
event. When the event is raised, the name of the active tool is displayed in an alert box.
// Define variable to hold name of Active Tool
var fwActiveToolForSWFs:String;
// Active Selection Change Event Handler
function onFwActiveToolChange()
{
MMExecute("alert('Tool Changed: " + fwActiveToolForSWFs + "');");
}
These are two of the most common events that you’ll need to handle in your custom panels, though
there are a number of other events raised by Fireworks, such as onFwStartMovie and onFwStopMovie,
raised when your panel starts and stops, respectively. The list of Fireworks events can be found in the
Extending Fireworks documentation at
Cross- Product Extensions ➤ Flash panels ➤ Events ➤ Creating
event handlers
.
Building panels with ActionScript 3
We’ve spent most of the chapter looking at how to create Flash panels using ActionScript 2. ActionScript
2 is more accessible for most hobbyist programmers than ActionScript 3, and you’ll find most exam-
ples of Flash panels available online today have been authored with ActionScript 2 (either because
they were authored prior to ActionScript 3, or because ActionScript 2 is more accessible). However,
many of the panels that ship with Fireworks CS4 have been reauthored using Flex and ActionScript 3.
Kommentare zu diesen Handbüchern