12 November 2007
It's best to have a basic understanding of ActionScript 3.0, the Fireworks DOM, and working with JavaScript in Fireworks. Refer to the following articles by Trevor McCauley for more details on how to create custom panels (using ActionScript 2.0):
Advanced
Custom panels are one of the features by which you can extend Fireworks to introduce new functionality into the tool or workflows into your team's procedures. You create or modify custom panels in Flash CS3 Professional and then export them as SWF files for use in Fireworks CS3. You can use ActionScript 2.0 or ActionScript 3.0 to extend these panels and handle Fireworks events.
This article focuses on handling Fireworks events in custom panels using ActionScript 3.0.
When an event is generated in Fireworks, it calls the IsFwCallbackInstalled function in an ActionScript 3.0 SWF file to find out if the event handling code is written in the custom panel. If the function returns true, Fireworks first executes the event code written in the custom panel and then executes its own event handling code. Figure 1 depicts the control flow for a Fireworks event.
Part 2 of Trevor's "Creating Fireworks panels" series shows a table containing all the events generated by Fireworks. To take advantage of these events in ActionScript 3.0 with Fireworks CS3, you need to write two functions for your custom panel:
The following example returns true when Fireworks checks for the events related to a Fireworks document being opened or closed. This tells Fireworks that it should call handlers for those events for the custom panel when the actions occur:
function IsFwCallbackInstalled( funcName:String ):Boolean
{
switch( funcName )
{
case "onFwDocumentOpen":
return true;
case "onFwDocumentClose":
return true;
case "setfwActiveToolForSWFs":
return true;
}
return false;
}
onFwDocumentOpen and OnFwDocumentClose events. An alert message should pop up whenever a document is open (see Figure 2) or closed (see Figure 3):function OpenDoc()
{
MMExecute('alert("Opening Document");');
}
function CloseDoc ()
{
MMExecute('alert("Closing Document");');
}
You must register all functions written in ActionScript 3.0 that Fireworks calls. Fireworks cannot call any function in a custom panel that is not registered. In order to register a function, add the following line of code to it:
ExternalInterface.addCallback("<alias name>",<function name>);
where:
For example, to register IsFwCallbackInstalled, you would need to add the following line of code:
ExternalInterface.addCallback("IsFwCallbackInstalled",IsFwCallbackInstalled);
Similarly, for OpenDoc and CloseDoc, you would need to add the following lines of code, respectively:
ExternalInterface.addCallback("onFwDocumentOpen",OpenDoc);
ExternalInterface.addCallback("onFwDocumentClose",CloseDoc);
ActionScript 3.0 functions that handle events are executed in Fireworks only if they and IsFwCallbackInstalled are registered, and if IsFwCallbackInstalled returns true when that event is generated.
The sample file accompanying this article, fw_events_as3.zip, contains two files:
Now when you restart Fireworks, the new panel will be added. Select Windows > ActionScript to open this new panel (see Figure 4). This panel lists the current tool in use and shows the alert message whenever a document is opened or closed.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
| 09/07/2011 | How do I use FXG XML markup in Shape subclasses? |
|---|---|
| 10/15/2010 | Flex4 Dotted Line |
| 06/25/2010 | ComboBox that uses a NativeMenu (Air API) |
| 05/21/2010 | Localizing a Creative Suite 5 extension |