Specifying the target of an action – Adobe Extending Flash Professional CS5 User Manual
Page 32
10
EXTENDING FLASH PROFESSIONAL
Introduction
Last updated 5/2/2011
To access the document that is currently focused, use the statement
flash.getDocumentDOM()
or
fl.getDocumentDOM()
. See
. The latter is the syntax used in most of the examples in this
document.
To find a particular document in the
fl.documents
array, iterate through the array and test each document for its
document.name
property
.
All the objects in the DOM that aren’t listed in the previous table (see “
The Flash Document Object Model
are accessed from the Document object. For example, to access the library of a document, you use the
document.library
property, which retrieves a library object:
fl.getDocumentDOM().library
To access the array of items in the library, you use the
library.items
property; each element in the array is an Item
object:
fl.getDocumentDOM().library.items
To access a particular item in the library, you specify a member of the
library.items
array:
fl.getDocumentDOM().library.items[0]
In other words, the library object is a child of the Document object, and the Item object is a child of the library object.
For more information, see
, and
Specifying the target of an action
Unless otherwise specified, methods affect the current focus or selection. For example, the following script doubles the
size of the current selection because no particular object is specified:
fl.getDocumentDOM().scaleSelection(2, 2);
In some cases, you might want an action to specifically target the currently selected item in the Flash document. To do
this, use the array that the
document.selection
). The first element in
the array represents the currently selected item, as shown in the following example:
var accDescription = fl.getDocumentDOM().selection[0].description;
The following script doubles the size of the first element on the Stage that is stored in the element array, instead of the
current selection:
var element = fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0];
if (element) {
element.width = element.width*2;
element.height = element.height*2;
}
You can also do something such as loop through all the elements on the Stage and increase the width and height by a
specified amount, as shown in the following example:
var elementArray =
fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements;
for (var i=0; i < elementArray.length; i++) {
var offset = 10;
elementArray[i].width += offset;
elementArray[i].height += offset;
}