The Flash Document Object Model
21
All the objects in the DOM that aren’t listed in the previous table (see
“The Flash Document
Object Model” on page 19
) are accessed from the
Document
object. For example, to access the
library of a document, you use the
library
property of the
Document
object, which retrieves a
library object
:
fl.getDocumentDOM().library
To access the array of items in the library, you use the
items
property of the
Library
object; 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
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.
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
property contains. 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].= offset;
}
Содержание FLASH MX 2004-FLASH JAVASCRIPT DICTIONARY
Страница 1: ...Flash JavaScript Dictionary ...
Страница 16: ...16 Contents ...
Страница 40: ...40 Chapter 2 Top level functions ...
Страница 368: ...368 Chapter 3 Objects ...
Страница 386: ...386 Chapter 4 C Level Extensibility ...