User Guide

10 Chapter 2: The Fireworks Object Model
Accessing a Fireworks document
All the functions listed in “Document functions” on page 104 are methods of the Document
object, which represents a Fireworks document. To perform a function on a Document object,
you must first get the Document Object Model (DOM) of the document. You then call the
functions as methods of that DOM.
Note: You can use methods that operate on a document’s DOM only on open documents.
To use a DOM function with a document other than the active document, use the following
syntax; note that
documentIndex is a zero-based index that specifies which document the
command will affect.
fw.documents[documentIndex].functionName();
To use a DOM function with the active document, use
fw.getDocumentDOM().functionName(), see fw.getDocumentDOM().
Passing values
For all properties that are not read-only, you can pass values to change elements of a document.
For example, the following command sets the fifth brush in the third open document to a
square shape:
fw.documents[2].brushes[4].shape = "square";
The preceding example includes the following properties:
documents is a property of the Fireworks object and contains an array of Document objects.
brushes is a property of the Document object and contains an array of Brush objects.
shape is a property of the Brush object.
Note: Throughout this manual, optional arguments are enclosed in {braces}.
Fireworks Object Model calls and API calls
In some cases, you can use Fireworks Object Model calls or API calls to perform the same
operations. In other cases, a certain function might be available in either the Fireworks Object
Model or the API, but not in both.
For example, if the first open document is the current document, the first code fragment has the
same effect as the second and third code fragments. The
fw.getDocumentDOM() function
references the current document (see Accessing a Fireworks document” on page 10).
fw.getDocumentDOM().setDocumentResolution({pixelsPerUnit:72, units:"inch"});
fw.documents[0].resolution =72;
fw.documents[0].resolutionUnits ="inch";