
215
EXTENDING FIREWORKS: DEVELOPING AN EFFECTIVE WORKFLOW USING JAVASCRIPT AND FLASH
// onFwActiveSelectionChange Event Handler
// Get the color of the currently selected object
// (only works for solid fills)
function onFwActiveSelectionChange()
{
currentColor = MMExecute("fw.selection[0].pathAttributes.fillColor");
colorPicker_mc.SetColor(currentColor);
}
The first event that we are handling is IsFwCallbackInstalled. Before sending an event like
onFwActiveSelectionChange to the panel, Fireworks first raises the IsFwCallbackInstalled event as
a sort of polling mechanism. The event passes a single string argument representing the name of the
event Fireworks is about to raise. If you want to handle the event, your function should return true;
otherwise, it should return false. This is commonly achieved by using a switch statement, as demon-
strated in the previous code sample.
When you return true, the actual event is raised on your panel, and your event handler code is exe-
cuted. So, handling Fireworks events in ActionScript 3 is really a two- step process. You first handle the
IsFwCallbackInstalled event and respond with the true value to events that you want to handle,
and then you actually handle the event you’re interested in.
The updated sample in the AS3 Flash Panel folder includes a fully working ActionScript 3 version
of the Draw Rect example. In the ActionScript 3 version, the onFwActiveSelectionChange event is
handled, and the value of the ColorPicker is updated based on the fill value of the selected object.
Creating ActionScript 3 panels in Flex
This section assumes you are familiar with the Flex environment and the Flex programming model.
Aside from the differences between Flex and Flash, enabling your Flex project to work with the work-
flow presented in this chapter is a natural evolution of what you’ve seen thus far. The following code
shows the <mx:Application> tag of DrawRect.mxml, the Flex version of the Draw Rect example we’ve
been using:
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
minWidth="250" minHeight="190"
initialize="init()"
creationComplete="UpdateLayout()"
width="250" height="200">
<mx:Script>
<![CDATA[
include "jsf/jsfCode.as";
import mx.containers.HBox;
import adobe.utils.*;
...
Commentaires sur ces manuels