Specifying the target of an action, Summary of the dom structure – Adobe Extending Flash Professional CS4 User Manual

Page 33

Advertising
background image

11

EXTENDING FLASH CS4 PROFESSIONAL

Introduction

All the objects in the DOM that aren’t listed in the previous table (see “

The Flash Document Object Model

” on page 9)

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

document.library

,

library object

,

library.items

library.items

, and

Item 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 (see

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;

}

Summary of the DOM structure

The following list displays the DOM structure in outline format. Numbers at the beginning of each line represent the
level of an object. For example, an object preceded by “03” is a child of next highest “02” object, which, in turn, is a
child of the next highest “01” object.

Advertising