
195
EXTENDING FIREWORKS: DEVELOPING AN EFFECTIVE WORKFLOW USING JAVASCRIPT AND FLASH
var cornerRadius = 0;
fw.getDocumentDOM().addNewRectanglePrimitive(myRect, cornerRadius);
That pretty much covers the details of line 1. A rectangle will be created with the specified bounding
box and corner radius. The second line sets the color of the newly created rectangle by calling the
setFillColor method. setFillColor accepts a hexadecimal color string of the format #RRGGBB or
#RRGGBBAA, where AA represents opacity (alpha).
Remember how we said earlier that most methods operate on selected objects? You may be wonder-
ing how we selected the rectangle that was just added. The answer is that we didn’t need to. Consider
any time that you’ve drawn a rectangle on the canvas—after drawing the rectangle, it’s automatically
selected, right? The same is true when you add an object via code; it becomes the active selection.
Experiment with the values passed to addNewRectanglePrimitive and setFillColor, save Draw Rect.
jsf, and rerun the command within Fireworks. You can get immediate feedback on changes to your
code via the
Commands menu. You have now performed actions that you will perform countless times
if you proceed with Fireworks extension development (change code, save, test in Fireworks).
Step 2: Creating a Flash UI
The first phase of this workflow focuses on creating a working JSF file and testing that file in Fireworks.
The sample we looked at was extremely simple and didn’t require much testing. Really complex pan-
els, however, can often be difficult to debug. It’s sometimes hard to determine whether the bug is in
your JSF or in your panel’s ActionScript. By working with and testing pure JSF via the
Commands menu
before moving into a panel, you can be confident that the underlying JSF is working correctly.
Creating a document and adding a button
Now that you have a working, tested JSF file, it’s time to cre-
ate a command panel that gives the underlying command a
face. We’ll keep things simple at first and show you how to
create a panel in Flash that executes the JSF code defined in
Draw Rect.jsf.
1. Start by creating a new Flash document (select an
ActionScript 2 project for now).
2. Set the document width to 250 pixels (px) and the
height to 300 px. The size that you define on your
document becomes the minimum size of the panel in
Fireworks. The panel can be sized larger than this in
Fireworks but never smaller.
3. Now, add a Button component to the stage (note that
Flash uses the term “stage” instead of “canvas”), and
give it an instance name of
executeJSF_btn.
4. Set the component’s Label property to Execute JSF, as
shown in Figure 11-2.
Figure 11‑2. Adding a Button to the stage in
Flash
Kommentare zu diesen Handbüchern