Add Life to the Web, Afterburner, Aftershock, Andromedia, Allaire, Animation PowerPack, Aria, Attain, Authorware,
Authorware Star, Backstage, Bright Tiger, Clustercats, ColdFusion, Contribute, Design In Motion, Director, Dream Templates,
Dreamweaver, Drumbeat 2000, EDJE, EJIPT, Extreme 3D, Fireworks, Flash, Flash Lite, Flex, Fontographer, FreeHand,
Generator, HomeSite, JFusion, JRun, Kawa, Know Your Site, Knowledge Objects, Knowledge Stream, Knowledge Track,
LikeMinds, Lingo, Live Effects, MacRecorder Logo and Design, Macromedia, Macromedia Action!, Macromedia Breeze,
Macromedia Flash, Macromedia M Logo and Design, Macromedia Spectra, Macromedia xRes Logo and Design, MacroModel,
Made with Macromedia, Made with Macromedia Logo and Design, MAGIC Logo and Design, Mediamaker, Movie Critic,
Open Sesame!, Roundtrip, Roundtrip HTML, Shockwave, Sitespring, SoundEdit, Titlemaker, UltraDev, Web Design 101, what
the web can be, and Xtra are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United
States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned
within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be
registered in certain jurisdictions including internationally.
Third-Party Information
This guide contains links to third-party websites that are not under the control of Macromedia, and Macromedia is not
responsible for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your
own risk. Macromedia provides these links only as a convenience, and the inclusion of the link does not imply that Macromedia
endorses or accepts any responsibility for the content on those third-party sites.
Speech compression and decompression technology licensed from Nellymoser, Inc. (www.nellymoser.com).
Sorenson™ Spark™ video compression and decompression technology licensed from Sorenson Media, Inc.
APPLE COMPUTER, INC. MAKES NO WARRANTIES, EITHER EXPRESS OR IMPLIED, REGARDING THE
ENCLOSED COMPUTER SOFTWARE PACKAGE, ITS MERCHANTABILITY OR ITS FITNESS FOR ANY
PARTICULAR PURPOSE. THE EXCLUSION OF IMPLIED WARRANTIES IS NOT PERMITTED BY SOME STATES.
THE ABOVE EXCLUSION MAY NOT APPLY TO YOU. THIS WARRANTY PROVIDES YOU WITH SPECIFIC
LEGAL RIGHTS. THERE MAY BE OTHER RIGHTS THAT YOU MAY HAVE WHICH VARY FROM STATE TO
STATE.
The documents on this site assume you are familiar with JavaScript or ActionScript syntax and
with basic programming concepts such as functions, parameters, and data types. They also
assume that you understand the concept of working with objects and properties. For a reference
on JavaScript, see the Netscape JavaScript documentation.
Netscape DevEdge Online has a JavaScript Developer Central site (http://
developer.netscape.com/tech/javascript/index.html) that contains documentation and articles
useful for understanding JavaScript. The most valuable resource is the Core JavaScript Guide.
The ActionScript language lets you write scripts to perform actions in the Macromedia Flash
Player environment (that is, while a SWF file is playing). The Flash JavaScript API (JSAPI) lets
you write scripts to perform several actions in the Flash authoring environment (that is, while a
user has the Flash program open). You can write scripts that act like commands and scripts that
add tools to the Tools panel. These scripts can be used to help automate the authoring process.
The Flash JSAPI is designed to resemble the Macromedia Dreamweaver and Macromedia
Fireworks JavaScript API (which were designed based on the Netscape JavaScript API). The Flash
JSAPI is based on a Document Object Model (DOM), which allows Flash documents to be
accessed using JavaScript objects. The Flash JSAPI includes all elements of the Netscape
JavaScript API, plus the Flash DOM. These added objects and their methods and properties are
described in this document. You can use any of the elements of the native JavaScript language in a
Flash script, but only elements that make sense in the context of a Flash document will have
an effect.
17
You can use Macromedia Flash MX 2004 Professional or your preferred text editor to write or
edit Flash JavaScript (JSFL) files. If you use Flash Professional, these files have a .jsfl extension by
default. To make a script appear in the Commands menu, save its JSFL file in the following
folder:
• Windows 2000 or Windows XP:
C:\Documents and Settings\user\Local Settings\ Application Data\Macromedia\
Flash MX2004\language\Configuration\Commands
Hard Drive/Users/userName/Library/Application Support/Macromedia/Flash MX 2004/
language/Configuration/Tools
If a JSFL file has other files that go with it, such as XML files, they should be stored in the same
directory as the JSFL file.
You can also create a JSFL file by selecting one or more commands in the History panel and then
clicking the Save As Command button in the History panel or selecting the Save As Command
from the Options pop-up menu. The command (JSFL) file is saved in the Commands folder. You
can then open the file and edit it the same as any other script file.
To run a script, do one of the following:
• Select Commands > Command Name.
• Select Commands > Run Command and then select the script to run.
To add a tool implemented in a JSFL file to the Flash Tools panel:
1.
Copy the JSFL file for the tool and any other associated files to the Tools folder.
You can embed individual JSAPI commands in ActionScript files by using the MMExecute()
command, which is documented in the Flash MX 2004 ActionScript Language Reference. However,
the
MMExecute() command has an effect only when it is used in the context of a custom user-
interface element, such as a component Property inspector, or a SWF panel within the authoring
environment. Even if called from ActionScript, JSAPI commands have no effect in Flash Player or
outside the authoring environment.
The JSAPI also contains a number of methods that let you implement extensibility using a
combination of JavaScript and custom C code. For more information, see Chapter 4, “C-Level
Extensibility,” on page 369.
Flash JavaScript objects contain properties and methods. Properties, each defined as a primitive
type such as Boolean, integer, array, float, or reference data types such as color, object, point, rect,
and String, are used to describe the object. Methods are used to perform a function on the object.
To access the properties or methods of an object, dot notation is used. Also, most objects have
getProperty() and setProperty() methods, which get the value for a specified property or set
the value for a specified property. Most methods take parameters that are used to specify different
options for the method.
The JavaScript interpreter in Flash is the Mozilla SpiderMonkey engine, version 1.5, which is
available on the web at http://www.mozilla.org/js/spidermonkey/. SpiderMonkey is one of the
two reference implementations of the JavaScript language developed by Mozilla.org. It is the same
engine that is embedded in the Mozilla browser.
SpiderMonkey implements the entire core JavaScript language as defined in the ECMA-262
specification. It is fully compliant with ECMA-262 Edition 3. Only the browser-specific host
objects, which are not part of the ECMA-262 specification, are not supported.
All “Core JavaScript” sections of Netscape’s JavaScript documentation at http://
devedge.netscape.com/central/javascript/ apply to the Flash JavaScript interpreter. All “Client-
Side JavaScript” sections do not apply because they only apply to browser environments.
SpiderMonkey is also used in Fireworks MX 2004, Dreamweaver MX 2004, Director MX 2004
and Flash Communication Server MX.
The Flash Document Object Model
The DOM for the Flash JavaScript API consists of a set of top-level functions (see “Top-level
functions” on page 25) and the top-level flash object. The
available to a script because it always exists when the Flash authoring environment is open. When
referring to this object, you can use
flash or fl. For example, to close all open files, you can use
either of the following statements:
flash.closeAll();
fl.closeAll();
flash object is guaranteed to be
The Flash Document Object Model19
The flash object contains the following child objects:
ObjectHow to access
componentsPanel objectUse fl.componentsPanel to access the componentsPanel object. This
object corresponds to the Components panel in the Flash authoring
environment.
Document objectUse
drawingLayer objectUse
Effect objectUse
Math objectUse
outputPanel objectUse
Tools object
ToolObj objectUse fl.
XMLUI objectUse
fl.documents to retrieve an array of all the open documents; use
fl.documents[index] to access a particular document; use
fl.getDocumentDOM() to access the current document (the one with
focus).
fl.drawingLayer to access the drawingLayer object.
fl.effects to retrieve an array of effect descriptors that
corresponds to the effects registered when Flash starts; use
fl.effects[index] to access a particular effect; use fl.activeEffect to
access the effect descriptor for the current effect being applied.
fl.Math to access the Math object.
fl.outputPanel to access the outputPanel object. This object
corresponds to the Output panel in the Flash authoring environment.
fl.tools is an object that has a toolObjs property. The toolObjs
property is an array of
a tool in the Flash Tools panel.
tools.toolObjs to retrieve an array of all tool objects (see
tools.toolObjs); use fl.tools.activeTool to access the currently
active tool object (see
fl.xmlui to access an XML User Interface (XMLUI) object. The
XMLUI object provides the ability to get and set properties of an XMLUI
dialog box.
toolObj objects. Each toolObj object represents
tools.activeTool).
The Document object
An important property of the top-level
flash object is the documents property. The documents
property contains an array of Document objects that each represent one of the FLA files currently
open in the authoring environment. The properties of each Document object represent most of
the elements that a FLA file can contain. Therefore, a large portion of the DOM is composed of
child objects and properties of the
To refer to the first open document, for example, use the statement
fl.documents[0]. The first document is the first Flash document that was opened during the
Document object.
flash.documents[0]. or
current session in the authoring environment. When the first opened document is closed, the
indexes of the other open documents are decremented.
To find a particular document's index use
To access the document that is currently focused, use the statement
fl.getDocumentDOM(). The latter is the syntax used in most of the examples in this document.
To find a particular document in the
document for its
20Chapter 1: Introduction
name property.
fl.findDocumentIndex(nameOfDocument).
flash.getDocumentDOM() or
documents array, iterate through the array and test each
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
library of a document, you use the
library property of the Document object, which retrieves a
Document object. For example, to access the
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:
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;
}
The Flash Document Object Model21
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.
In some cases, an object is available by specifying a property of its parent object. For example, the
document.timelines property contains an array of Timeline objects. These properties are
noted in the following outline.
Finally, some objects are subclasses of other objects, rather than being children of other objects.
An object that is a subclass of another object has methods and/or properties of its own in addition
to the methods and properties of the other object (the superclass). Subclasses share the same level
in the hierarchy as their superclass. For example, Item is a superclass of BitmapItem. These
relationships are illustrated in the following outline:
Included with this documentation is a sample Flash JSAPI script named PolyStar.jsfl. (You can
download the file at www.macromedia.com/go/jsapi_info_en.) This script replicates the PolyStar
tool that can be found in the Flash Tools panel. The PolyStar.jsfl file demonstrates how to build
the PolyStar tool using the JSAPI. It includes detailed comments that describe what the lines of
code are doing. Read this file to gain a better understanding of how the JSAPI can be used.
Flash MX 2004 includes an earlier version of the PolyStar.jsfl script that must be removed in order
to use the updated PolyStar.jsfl file.
To remove the earlier version of the PolyStar.jsfl that was installed with Flash MX 2004:
In the Customize Tools Panel dialog box, click the Rectangle tool on the left side of the dialog
box.
The Rectangle tool and the PolyStar tool should now be listed in the Current Selection list on
the right side of the dialog box.
3.
Select the PolyStar tool in the Current Selection list.
4.
Click Remove.
5.
Click OK.
6.
Quit Flash.
7.
Remove only the PolyStar.jsfl file from the appropriate Tools folder listed in “Overview of the
Macromedia Flash JavaScript API” on page 17. The PolyStar.xml and PolyStar.png files are
needed by the new PolyStar.jsfl file that you will install later. When you restart Flash, the
PolyStar tool no longer appears in the Customize Tools Panel dialog box.
The PolyStar example23
To install the updated PolyStar example files:
1.
Copy the new PolyStar.jsfl file to the Tools folder. The PolyStar.xml and PolyStar.png files that
you see in this folder are needed by the new PolyStar.jsfl file.
2.
Restart Flash.
3.
Select Edit > Customize Tools Panel (Windows) or Flash > Customize Tools Panel
(Macintosh). You should see PolyStar tool in the available tools list.
4.
Click the Rectangle tool at the left side of the Customize Tools Panel dialog box. The Rectangle
Tool should appear in the Current Selection list at the right side of the dialog box.
5.
Select the PolyStar tool from the Available Tools list.
6.
Click Add.
7.
Click OK.
The PolyStar tool now appears in the Rectangle tool pop-up menu.
24Chapter 1: Introduction
CHAPTER 2
Top-level functions
This chapter describes the top-level functions that are available when creating extensible tools.
The following list shows the functions in alphabetical order:
This function is called when the extensible tool becomes active (that is, when the tool is selected
in the Tools panel). Any setup the tool needs to do should be performed in this function.
Example
function activate() {
fl.trace( "Tool is active" );
}
26Chapter 2: Top-level functions
configureEffect()
Availability
Flash MX 2004.
Usage
function configureEffect() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called once at load time of Flash and is a good place for global initialization of
your effect. The per instance parameter data for an effect cannot be accessed here.
See also
executeEffect()
, removeEffect()
configureEffect()27
configureTool()
Availability
Flash MX 2004.
Usage
function configureTool() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when Macromedia Flash opens and the tool is loaded. Use this function to
set any information Flash needs to know about the tool.
Example
The following examples show two possible implementations of this function:
This function is called when the tool becomes inactive (that is, when the active tool changes from
this tool to another one). Use this function to perform any cleanup the tool needs.
Example
function deactivate() {
fl.trace( "Tool is no longer active" );
}
deactivate()29
executeEffect()
Availability
Flash MX 2004.
Usage
function executeEffect() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when the user first applies an effect or changes an effect's properties. The
code contained in this function is responsible for modifying the original object(s) to accomplish
the desired effect. It is also responsible for copying the original to another hidden layer if
necessary for the
See also
configureEffect()
removeEffect function
, removeEffect()
30Chapter 2: Top-level functions
keyDown()
Availability
Flash MX 2004.
Usage
function keyDown() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when the tool is active and the user presses a key. The script should call
tools.getKeyDown() to determine which key was pressed.
Example
function keyDown() {
fl.trace("key " + fl.tools.getKeyDown() + " was pressed");
}
keyDown()31
keyUp()
Availability
Flash MX 2004.
Usage
function keyUp() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when the tool is active and a key is released.
Example
function keyUp() {
fl.trace("Key is released");
}
32Chapter 2: Top-level functions
mouseDoubleClick()
Availability
Flash MX 2004.
Usage
function mouseDoubleClick() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when the mouse button is double-clicked on the Stage.
Example
function mouseDblClk() {
fl.trace("Mouse was double-clicked");
}
mouseDoubleClick()33
mouseDown()
Availability
Flash MX 2004.
Usage
function mouseDown( [ pt ] ) {
// statements
}
Parameters
pt
A point that specifies the location of the mouse when the button is pressed. It is passed to the
function when the mouse button is pressed. This parameter is optional.
Returns
Nothing.
Description
This function is called whenever the tool is active and the mouse button is pressed while the
pointer is over the Stage.
Example
function mouseDown() {
fl.trace("Mouse button has been pressed");
}
34Chapter 2: Top-level functions
mouseMove()
Availability
Flash MX 2004.
Usage
function mouseMove( [ pt ] ) {
// statements
}
Parameters
pt
A point that specifies the current location of the mouse. It is passed to the function whenever
the mouse moves, which tracks the mouse location. If the Stage is in edit or edit-in-place mode,
the point coordinates are relative to the object being edited. Otherwise, the point coordinates are
relative to the Stage. This parameter is optional.
Returns
Nothing.
Description
This function is called whenever the mouse moves over a specified point on the Stage. The mouse
button can be down or up.
Example
function mouseMove() {
fl.trace("moving");
}
mouseMove()35
mouseUp()
Availability
Flash MX 2004.
Usage
function mouseUp() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called whenever the mouse button is released after being pressed on the Stage.
Example
function mouseUp() {
fl.trace("mouse is up");
}
36Chapter 2: Top-level functions
notifySettingsChanged()
Availability
Flash MX 2004.
Usage
function notifySettingsChanged() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called whenever a tool is active and the user changes its options in the Property
inspector. You can use the
options.
Example
function notifySettingsChanged() {
var theTool = fl.tools.activeTool;
var newValue = theTool.myProp;
}
tools.activeTool property to query the current values of the
notifySettingsChanged()37
removeEffect()
Availability
Flash MX 2004.
Usage
function removeEffect() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called when the user changes an effect's properties or uses the "remove effect"
menu item. The code contained in this function is responsible for returning the object(s) to their
original state. For example, if the effect broke a text string apart, the responsibility of the
removeEffect() method would be to remove the text string that was broken apart and replace it
with the original string.
See also
configureEffect()
, executeEffect()
38Chapter 2: Top-level functions
setCursor()
Availability
Flash MX 2004.
Usage
function setCursor() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
This function is called whenever the mouse moves, to allow the script to set custom pointers. The
script should call
pointers correspond to which integer values, see
Example
function setCursor() {
fl.tools.setCursor( 1 );
}
tools.setCursor() to specify the pointer to use. For a list that shows which
tools.setCursor().
setCursor()39
40Chapter 2: Top-level functions
CHAPTER 3
Objects
This chapter describes the Flash JSAPI objects, listed in alphabetical order. The objects are listed
in the following table:
ObjectDescription
BitmapInstance objectThe BitmapInstance object is a subclass of the Instance object and
BitmapItem objectA BitmapItem object refers to a bitmap in the library of a document.
CompiledClipInstance object The CompiledClipInstance object is a subclass of the Instance
ComponentInstance objectThe ComponentInstance object is a subclass of the SymbolInstance
componentsPanel objectThe componentsPanel object, which represents the Components
Contour objectA Contour object represents a closed path of half edges on the
Document objectThe Document object represents the Stage.
drawingLayer objectThe drawingLayer object is accessible from JavaScript as a child of
Edge objectThe Edge object represents an edge of a shape on the Stage.
Effect objectThe Effect object represents an instance of a Timeline effect.
Element objectEverything that appears on the Stage is of the type Element.
EmbeddedVideoInstance
object
Fill objectThe Fill object contains all the properties of the Fill color setting of
flash objectThe flash object represents the Flash application.
folderItem objectThe folderItem object is a subclass of the Item object.
represents a bitmap in a frame.
The BitmapItem object is a subclass of the Item object.
object.
object and represents a component in a frame.
panel, is a property of the flash object and can be accessed by
fl.componentsPanel.
boundary of a shape.
the flash object.
The EmbeddedVideoInstance object is a subclass of the Instance
object.
the Tools panel or of a selected shape.
41
ObjectDescription
fontItem objectThe fontItem object is a subclass of the Item object.
Frame objectThe Frame object represents frames in the layer.
HalfEdge objectDirected side of the edge of a Shape object.
Instance objectThe Instance object is a subclass of the Element object.
Item objectThe Item object is an abstract base class.
Layer objectThe Layer object represents a layer in the Timeline.
library objectThe library object represents the Library panel.
LinkedVideoInstance objectThe LinkedVideoInstance object is a subclass of the Instance object.
Math objectThe Math object is available as a read-only property of the flash
object; see
fl.Math.
Matrix objectThe Matrix object represents a transformation matrix.
outputPanel objectThe outputPanel object represents the Output panel, which displays
troubleshooting information such as syntax errors.
Parameter objectThe Parameter object type is accessed from the
screen.parameters
array (which corresponds to the screen Property inspector in the
Flash authoring tool) or by the
componentInstance.parameters array
(which corresponds to the component Property inspector in the
authoring tool).
Path objectThe Path object defines a sequence of line segments (straight,
curved, or both), which you typically use when creating extensible
tools.
Screen objectThe Screen object represents a single screen in a slide or form
document.
ScreenOutline objectThe ScreenOutline object represents the group of screens in a slide
or form document.
Shape objectThe Shape object is a subclass of the Element object. The Shape
object provides more precise control than the drawing APIs for
manipulating or creating geometry on the Stage.
SoundItem objectThe SoundItem object is a subclass of the Item object. It represents
a library item used to create a sound.
Stroke objectThe Stroke object contains all the settings for a stroke, including the
custom settings.
SymbolInstance objectThe SymbolInstance object is a subclass of the Instance object and
represents a symbol in a frame.
SymbolItem objectThe SymbolItem object is a subclass of the Item object.
Text objectThe Text object represents a single text item in a document.
TextAttrs objectThe TextAttrs object contains all the properties of text that can be
applied to a subselection. This object is a subclass of the Text
object.
42Chapter 3: Objects
ObjectDescription
TextRun objectThe TextRun object represents a run of characters that have
Timeline objectThe Timeline object represents the Flash Timeline, which can be
ToolObj objectA ToolObj object represents an individual tool in the Tools panel.
Tools objectThe Tools object is accessible from the Flash object (
Vertex objectThe Vertex object is the part of the shape data structure that holds
VideoItem objectThe VideoItem object is a subclass of the Item object.
XMLUI objectThe XMLUI object provides the ability to get and set properties of an
attributes that match all of the properties in the TextAttrs object.
accessed for the current document by
fl.getDocumentDOM().getTimeline().
fl.tools).
the coordinate data.
XMLUI dialog box, and accept or cancel out of one.
BitmapInstance object
Inheritance Element object > Instance object > BitmapInstance object
Availability
Flash MX 2004.
Description
The BitmapInstance object is a subclass of the Instance object and represents a bitmap in a frame.
Method summary for the BitmapInstance object
In addition to the Instance object methods, you can use the following methods with the
BitmapInstance object:
MethodDescription
bitmapInstance.getBits()Method; lets you create bitmap effects by getting the bits out of the
bitmap, manipulating them, and then returning them to Flash.
bitmapInstance.setBits()Method; sets the bits of an existing bitmap element.
Property summary for the BitmapInstance object
In addition to the Instance object properties, you can use the following properties with the
BitmapInstance object.
PropertyDescription
bitmapInstance.hPixels Read-only; an integer that represents the width of the bitmap, in
bitmapInstance.vPixels Read-only; an integer that represents the height of the bitmap, in
pixels.
pixels.
BitmapInstance object43
bitmapInstance.getBits()
Availability
Flash MX 2004.
Usage
bitmapInstance.getBits()
Parameters
None.
Returns
An object that contains width, height, depth, bits, and, if the bitmap has a color table, cTab
properties. The
the form
Note: The byte array is meaningful only when referenced by an external library. You typically use it
only when creating an extensible tool or effect.
Description
bits element is an array of bytes. The cTab element is an array of color values of
"#rrggbb". The length of the array is the length of the color table.
Method; lets you create bitmap effects by getting the bits out of the bitmap, manipulating them,
and then returning them to Flash. See also
Example
bitmapInstance.setBits().
The following code creates a reference to the currently selected object; tests whether the object is a
bitmap; and traces the height, width, and bit depth of the bitmap:
var isBitmap = fl.getDocumentDOM().selection[0].instanceType;
if(isBitmap == "bitmap"){
Read-only property; an integer that represents the width of the bitmap, in pixels.
Example
The following code retrieves the width of the bitmap in pixels:
// Get the number of pixels in the horizontal dimension.
var bmObj = fl.getDocumentDOM().selection[0];
44Chapter 3: Objects
var isBitmap = bmObj.instanceType;
if(isBitmap == "bitmap"){
var numHorizontalPixels = bmObj.hPixels;
}
bitmapInstance.setBits()
Availability
Flash MX 2004.
Usage
bitmapInstance.setBits(bitmap)
Parameters
bitmap
An object that contains height, width, depth, bits, and cTab properties. The
height, width, and depth propertiesare integers. The bits property is a byte array. The cTab
property is required only for bitmaps with a bit depth of 8 or less and is a string that represents a
color value in the form
Note: The byte array is meaningful only when referenced by an external library. You typically use it
only when creating an extensible tool or effect.
Returns
"#rrggbb".
Nothing.
Description
Method; sets the bits of an existing bitmap element. This lets you create bitmap effects by getting
the bits out of the bitmap, manipulating them, and then returning the bitmap to Flash.
Example
The following code tests whether the current selection is a bitmap, and then reduces the height of
the bitmap by 150 pixels:
var isBitmap = fl.getDocumentDOM().selection[0].instanceType;
if(isBitmap == "bitmap"){
var bits = fl.getDocumentDOM().selection[0].getBits();
bits.height = -150;
fl.getDocumentDOM().selection[0].setBits(bits);
}
bitmapInstance.vPixels
Availability
Flash MX 2004.
Usage
bitmapInstance.vPixels
Description
Read-only property; an integer that represents the height of the bitmap, in pixels.
BitmapInstance object45
Example
The following code gets the height of the bitmap in pixels:
// get the number of pixels in the vertical dimension
var bmObj = fl.getDocumentDOM().selection[0];
var isBitmap = bmObj.instanceType;
if(isBitmap == "bitmap"){
var numVerticalPixels = bmObj.vPixels;
}
46Chapter 3: Objects
CHAPTER 3
BitmapItem object
Inheritance Item object > BitmapItem object
Availability
Flash MX 2004.
Description
A BitmapItem object refers to a bitmap in the library of a document. The BitmapItem object is a
subclass of the Item object.
Property summary for the BitmapItem object
In addition to the Item object properties, the BitmapItem object has following properties:
PropertyDescription
bitmapItem.allowSmoothingProperty; a Boolean value. Set to true to allow smoothing of
a bitmap;
bitmapItem.compressionTypeProperty; a string that determines the type of image
compression applied to the bitmap.
bitmapItem.qualityProperty; an iinteger that specifies the quality of the bitmap
bitmapItem.useImportedJPEGQuality Property; a Boolean value. To use the default imported JPEG
quality, specify
false otherwise.
true; false otherwise.
Objects
bitmapItem.allowSmoothing
Availability
Flash MX 2004.
Usage
bitmapItem.allowSmoothing
Description
Property; a Boolean value. Set to true to allow smoothing of a bitmap; false otherwise.
Example
The following code sets the allowSmoothing property of the first item in the library of the
current document to
Property; an integer that specifies the quality of the bitmap. To use the default document quality,
specify -1; otherwise, specify an integer from 0 to 100. Available only for JPEG compression.
Example
The following code sets the quality property of the first item in the library of the current
document to 65:
Inheritance Element object > Instance object > CompiledClipInstance object
Availability
Flash MX 2004.
Description
The CompiledClipInstance object is a subclass of the Instance object. It is essentially an instance
of a movie clip that has been converted to a compiled clip library item.
Property summary for the CompiledClipInstance object
In addition to the properties of the Instance object, the CompiledClipInstance object has the
following properties:
PropertyDescription
compiledClipInstance.accName
compiledClipInstance.actionScript
compiledClipInstance.description
compiledClipInstance.forceSimple
compiledClipInstance.shortcut
compiledClipInstance.silent
compiledClipInstance.tabIndex
Property; a string that is equivalent to the Name field in the
Accessibility panel.
Property; a string that represents the ActionScript for this
instance; equivalent to
Property; a string that is equivalent to the Description field in
the Accessibility panel.
Property; a Boolean value that enables and disables the
children of the object to be accessible.
Property; a string that is equivalent to the Shortcut field in the
Accessibility panel.
Property; a Boolean value that enables or disables the
accessibility of the object; equivalent to the inverse logic of
Make Object Accessible setting in the Accessibility panel.
Property; an integer that is equivalent to the Tab Index field in
the Accessibility panel.
symbolInstance.actionScript.
Objects
compiledClipInstance.accName
Availability
Flash MX 2004.
Usage
compiledClipInstance.accName
Description
Property; a string that is equivalent to the Name field in the Accessibility panel. Screen readers
identify objects by reading the name aloud.
50Chapter 3: Objects
Example
// get the name of the object.
var theName = fl.getDocumentDOM().selection[0].accName;
// set the name of the object.
fl.getDocumentDOM().selection[0].accName = 'Home Button';
compiledClipInstance.actionScript
Availability
Flash MX 2004.
Usage
compiledClipInstance.actionScript
Description
Property; a string that represents the ActionScript for this instance; equivalent to
symbolInstance.actionScript.
Example
The following code assigns ActionScript to specified elements:
//assign some ActionScript to a specified Button compiled clip instance.
fl.getDocumentDOM().getTimeline().layers[0].frames[0].elements[0]
.actionScript = "on(click) {trace('button is clicked');}";
//assign some ActionScript to the currently selected Button compiled clip
instance.
fl.getDocumentDOM().selection[0].actionScript =
"on(click) {trace('button is clicked');}";
compiledClipInstance.description
Availability
Flash MX 2004.
Usage
compiledClipInstance.description
Description
Property; a string that is equivalent to the Description field in the Accessibility panel. The
description is read by the screen reader.
Example
The following example illustrates getting and setting the description property:
// get the description of the current selection
var theDescription = fl.getDocumentDOM().selection[0].description;
// set the description of the current selection
fl.getDocumentDOM().selection[0].description =
"This is compiled clip number 1";
CompiledClipInstance object51
compiledClipInstance.forceSimple
Availability
Flash MX 2004.
Usage
compiledClipInstance.forceSimple
Description
Property; a Boolean value that enables and disables the children of the object to be accessible.
This is equivalent to the inverse logic of the Make Child Objects Accessible setting in the
Accessibility panel. If
option being unchecked. If
forceSimple is true, it is the same as the Make Child Objects Accessible
forceSimple is false, it is the same as the Make Child Object
Accessible option being checked.
Example
The following example illustrates getting and setting the forceSimple property:
// query if the children of the object are accessible
var areChildrenAccessible = fl.getDocumentDOM().selection[0].forceSimple;
// allow the children of the object to be accessible
fl.getDocumentDOM().selection[0].forceSimple = false;
compiledClipInstance.shortcut
Availability
Flash MX 2004.
Usage
compiledClipInstance.shortcut
Description
Property; a string that is equivalent to the Shortcut field in the Accessibility panel. The shortcut is
read by the screen readers. This property is not available for dynamic text fields.
Example
The following example illustrates getting and setting the shortcut property:
// get the shortcut key of the object
var theShortcut = fl.getDocumentDOM().selection[0].shortcut;
// set the shortcut key of the object
fl.getDocumentDOM().selection[0].shortcut = "Ctrl+I";
compiledClipInstance.silent
Availability
Flash MX 2004.
Usage
compiledClipInstance.silent
52Chapter 3: Objects
Description
Property; a Boolean value that enables or disables the accessibility of the object; equivalent to the
inverse logic of Make Object Accessible setting in the Accessibility panel. That is, if
true, then Make Object Accessible is unchecked. If silent is false, then Make Object
silent is
Accessible is checked.
Example
The following example illustrates getting and setting the silent property:
// query if the object is accessible
var isSilent =fl.getDocumentDOM().selection[0].silent;
// set the object to be accessible
fl.getDocumentDOM().selection[0].silent = false;
compiledClipInstance.tabIndex
Availability
Flash MX 2004.
Usage
compiledClipInstance.tabIndex
Description
Property; an integer that is equivalent to the Tab Index field in the Accessibility panel. Creates a
tab order in which objects are accessed when the user presses the Tab key.
Example
The following example illustrates getting and setting the tabIndex property:
// get the tabIndex of the object.
var theTabIndex = fl.getDocumentDOM().selection[0].tabIndex;
// set the tabIndex of the object.
fl.getDocumentDOM().sele ction[0].tabIndex = 1;
The ComponentInstance object is a subclass of the SymbolInstance object and represents a
component in a frame.
Property summary for the ComponentInstance object
In addition to all the properties of the SymbolInstance object, the ComponentInstance object has
the following property:
PropertyDescription
componentInstance.parameters Read-only; an array containing the ActionScript 2.0 properties that
are accessible from the component Property inspector.
componentInstance.parameters
Availability
Flash MX 2004.
Objects
Usage
componentInstance.parameters
Description
Read-only property; an array containing the ActionScript 2.0 properties that are accessible from
the component Property inspector. See “Parameter object” on page 237.
Example
The following example illustrates getting and setting the parameters property:
var parms = fl.getDocumentDOM().selection[0].parameters;
parms[0].value = "some value";
54Chapter 3: Objects
CHAPTER 3
componentsPanel object
Availability
Flash MX 2004.
Description
The componentsPanel object, which represents the Components panel, is a property of the flash
object and can be accessed by
Method summary for the ComponentsPanel object
You can use the following method with the componentsPanel object:
PropertyDescription
componentsPanel.addItemToDocument() Adds the specified component to the document at the
Read-only property: an integer indicating the orientation of the contour. The value of the integer
is -1 if the orientation is counterclockwise, 1 if it is clockwise, and 0 if it is a contour with no area.
Example
The following example traverses all the contours of the selected shape and shows the value of the
orientation property of each contour in the Output panel:
var elt = fl.getDocumentDOM().selection[0];
elt.beginEdit();
var contourArray = elt.contours;
var contourCount = 0;
for (i=0; i<contourArray.length; i++) {
A string that specifies the name of the persistent data.
type Defines the type of data. The valid values for type are: "integer", "integerArray",
"double", "doubleArray", "string", and "byteArray".
data the value to add. Valid types depend on the type parameter.
Returns
Nothing.
Description
Method; stores specified data with the selected object(s). Data is written to the FLA file and is
available to JavaScript when the file reopens. Only symbols and bitmaps support persistent data.
See
document.removeDataFromSelection().
Example
The following example adds an integer value of 12 to the selected object:
A point that specifies the x and y coordinates of the location at which to add the
item. It uses the center of a symbol or the upper left corner of a bitmap or video.
item An Item object that specifies the item to add and the library from which to add it.
Returns
A Boolean value: true if successful; false otherwise.
Description
Method; adds an item from any open document or library to the specified Document object.
Example
The following example adds the first item from the library to the first document at the specified
location for the selected symbol, bitmap, or video:
var item = fl.documents[0].library.items[0];
fl.documents[0].addItem({x:0,y:0}, item);
66Chapter 3: Objects
The following example adds the symbol myMovieClip from the current document’s library to the
current document:
var itemIndex = fl.getDocumentDOM().library.findItemIndex("myMovieClip");
var theItem = fl.getDocumentDOM().library.items[itemIndex];
fl.getDocumentDOM().addItem({x:0,y:0}, theItem);
The following example adds the symbol myMovieClip from the second document in the
documents array to the third document in the documents array:
var itemIndex = fl.documents[1].library.findItemIndex("myMovieClip");
var theItem = fl.documents[1].library.items[itemIndex];
fl.documents[2].addItem({x:0,y:0}, theItem);
document.addNewLine()
Availability
Flash MX 2004.
Usage
document.addNewLine( startPoint
Parameters
startpoint
A pair of floating point numbers that specify the x and y coordinates where the line
, endpoint )
starts.
endpoint A pair of floating point numbers that specify the x and y coordinates where the line
ends.
Returns
Nothing.
Description
Method; adds a new path between two points. The method uses the document’s current stroke
attributes and adds the path on the current frame and current layer. This method works in the
same way as clicking on the line tool and drawing a line.
Example
The following example adds a line between the specified starting point and ending point:
bSuppressFill A Boolean value that, if set to true, causes the method to create the shape
without a fill. The default value is
bSuppressStroke A Boolean value that, if set to true, causes the method to create the shape
without a stroke. The default value is
Returns
A rectangle that specifies the bounds of the oval to be added.
false. This parameter is optional.
false. This parameter is optional.
Nothing.
Description
Method; adds a new oval in the specified bounding rectangle. This method performs the same
operation as the oval tool. The method uses the document’s current default stroke and fill
attributes and adds the oval on the current frame and layer. If
oval is drawn without a fill. If
stroke. If both
Example
bSuppressFill or bSuppressStroke are set to true, the method will do nothing.
bSurpressStroke is set to true, the oval is drawn without a
bSurpressFill is set to true, the
The following example adds a new oval within the specified coordinates:
added. This parameter specifies a pixel location for
roundness An integer value between 0 and 999 that specifies the roundness to use for the
A rectangle that specifies the bounds within which the new rectangle is
left, top, right, and bottom.
corners. The value is specified as number of points. The greater the value, the greater the
roundness.
bSuppressFill A Boolean value that, if set to true, causes the method to create the shape
without a fill. The default value is
false. This parameter is optional.
bSuppressStroke A Boolean value that, if set to true, causes the method to create the
rectangle without a stroke. The default value is
Returns
false. This parameter is optional.
Nothing.
Description
Method; adds a new rectangle or rounded rectangle, fitting it into the specified bounds. This
method performs the same operation as the rectangle tool. The method uses the document’s
current default stroke and fill attributes and adds the rectangle on the current frame and layer. If
the
bSuppressFill parameter is set to true, the rectangle is drawn without a fill. If the
bSuppressStroke parameter is set to true, the rectangle is drawn without a stroke. Either
bSuppressFill or bSuppressStroke must be set to false or the method does nothing.
Document object69
Example
The following example adds a new rectangle with no round corners within the specified
coordinates.
Specifies the name of the scene. If you do not specify a name, a new scene name is
generated.
Returns
A Boolean value: true if the scene is added successfully; false otherwise.
Description
Method; adds a new scene (Timeline object) as the next scene after the currently selected scene
and makes the new scene the currently selected scene. If the specified scene name already exists,
the scene is not added and the method returns an error.
Example
The following example adds a new scene named myScene after the current scene in the current
document. The variable
var success = flash.getDocumentDOM().addNewScene("myScene");
success will be true when the new scene is created; false otherwise
The following example adds a new scene using the default naming convention. If only one scene
exists, the newly created scene is named
fl.getDocumentDOM().addNewScene();
70Chapter 3: Objects
"Scene 2".
document.addNewText()
Availability
Flash MX 2004.
Usage
document.addNewText( boundingRectangle )
Parameters
boundingRectangle
pixels for
left, top, right, and bottom. The method applies the current text attributes. It
should be followed by calling
Returns
Specifies the size and location of the text field by providing locations in
setTextString() to populate the new text box.
Nothing.
Description
Method; inserts a new empty text field. See document.setTextString().
Example
The following example creates a new text field in the upper left corner of the Stage and then sets
the text string to
"left", "right", "top", "bottom", "vertical center", and "horizontal center".
bUseDocumentBounds A Boolean value that, if set to true, causes the method to align to the
A string that specifies how to align the selection. Valid values for alignmode are
bounds of the document. Otherwise, the method uses the bounds of the selected objects. The
default is
Returns
false. This parameter is optional.
Nothing.
Description
Method; aligns the selection. See document.distribute(),
document.setAlignToDocument(), and document.getAlignToDocument().
Document object71
Example
The following example aligns objects to left and to the Stage. This is equivalent to turning on the
To Stage setting in the Align panel and clicking the Align to Left button:
fl.getDocumentDOM().align("left", true);
document.allowScreens()
Availability
Flash MX 2004.
Usage
document.allowScreens()
Parameters
None.
Returns
Returns a Boolean value: true if dom.screenOutline can be used safely; false otherwise.
Description
Method; Used before using the document.screenOutline property. If this method returns the
value
true, you can safely access the screenOutline property. Flash displays an error if you
access the
Example
screenOutline property in a document without screens.
The following example determines whether screens methods can be used in the current
document:
if(fl.getDocumentDOM().allowScreens()) {
fl.trace("screen outline is available.");
}
else {
fl.trace("whoops, no screens.");
}
document.arrange()
Availability
Flash MX 2004.
Usage
document.arrange( arrangeMode )
Parameters
arrangeMode
arrangemode are "back", "backward", "forward", and "front". It provides the same
Specifies the direction in which to move the selection. The valid values for
capabilities as these options provide on the Modify >Arrange menu.
72Chapter 3: Objects
Returns
Nothing.
Description
Method; arranges the selection on the Stage. This method applies only to non-shape objects.
Example
The following example moves the current selection to the front:
fl.getDocumentDOM().arrange("front");
document.autoLabel
Availability
Flash MX 2004.
Usage
document.autoLabel
Description
Property; A Boolean value that is equivalent to the Auto Label check box in the Accessibility
panel. You can use this property to tell Flash to automatically label objects on the Stage with the
text associated with them.
Example
The following example gets the value of the autoLabel property and displays the result in the
Output panel:
var isAutoLabel = fl.getDocumentDOM().autoLabel;
fl.trace(isAutoLabel);
The following example sets the autoLabel property to true, telling Flash to automatically label
objects on the Stage:
fl.getDocumentDOM().autoLabel = true;
document.backgroundColor
Availability
Flash MX 2004.
Usage
document.backgroundColor
Description
Property; a color in hexidecimal format that represents the background color.
Example
The following example sets the background color to black:
fl.getDocumentDOM().backgroundColor = '#000000';
Document object73
document.breakApart()
Availability
Flash MX 2004.
Usage
document.breakApart()
Parameters
None.
Returns
Nothing.
Description
Method; performs a break-apart operation on the current selection.
Example
The following example breaks apart the current selection:
fl.getDocumentDOM().breakApart();
document.canEditSymbol()
Availability
Flash MX 2004.
Usage
document.canEditSymbol()
Parameters
None.
Returns
A Boolean value: true if the Edit Symbols menu and functionality are available for use; false
otherwise.
Description
Method; indicates whether the Edit Symbols menu and functionality are enabled. This is not
related to whether the selection can be edited. This method should not be used to test whether
fl.getDocumentDOM().enterEditMode() is allowed.
Example
The following example displays in the Output panel the state of the Edit Symbols menu and
functionality:
An object for the newly created symbol, or null if it cannot create the symbol.
Description
Method; converts the selected Stage item(s) to a new symbol. For information on defining linkage
and shared asset properties for a symbol, see Item object.
Example
The following examples create a movie clip symbol with a specified name, a button symbol with a
specified name, and a movie clip symbol with a default name:
Property; an integer that specifies the index of the active Timeline. You can set the active Timeline
by changing the value of this property; the effect is almost equivalent to calling
document.editScene(). The only difference is that you don’t get an error message if the index of
the Timeline is not valid (the property is simply not set, which causes silent failure).
See
document.getTimeline().
Example
The following example displays the index of the current Timeline.
var myCurrentTL = fl.getDocumentDOM().currentTimeline;
fl.trace("The index of the current timeline is: "+ myCurrentTL);
The following example changes the active Timeline from the main Timeline to a scene named
"myScene".
var i = 0;
var curTimelines = fl.getDocumentDOM().timelines;
while(i < fl.getDocumentDOM().timelines.length){
if(curTimelines[i].name == "myScene"){
fl.getDocumentDOM().currentTimeline = i;
}
80Chapter 3: Objects
++i;
}
document.deletePublishProfile()
Availability
Flash MX 2004.
Usage
document.deletePublishProfile()
Parameters
None.
Returns
An integer that is the index of the new current profile. If a new profile is not available, the method
leaves the current profile unchanged and returns its index.
Description
Method; deletes the currently active profile, if there is more than one. There must be at least one
profile left. See
Example
document.addNewPublishProfile().
The following example deletes the currently active profile, if there is more than one, and displays
the index of the new currently active profile:
A Boolean value: true if the scene is successfully deleted; false otherwise.
Description
Method; deletes the current scene (Timeline object) and, if the deleted scene was not the last one,
sets the next scene as the current Timeline object. If the deleted scene was the last one, it sets the
first object as the current Timeline object. If only one
the value
false.
Timeline object (scene) exists, it returns
Document object81
Example
Assuming there are three scenes (Scene0, Scene1, and Scene2) in the current document, the
following example makes
fl.getDocumentDOM().editScene(2);
var success = fl.getDocumentDOM().deleteScene();
Scene2 the current scene and then deletes it:
document.deleteSelection()
Availability
Flash MX 2004.
Usage
document.deleteSelection()
Parameters
None.
Returns
Nothing.
Description
Method; deletes the current selection on the Stage. Displays an error message if there is no
selection.
Example
The following example deletes the current selection in the document:
fl.getDocumentDOM().deleteSelection();
document.description
Availability
Flash MX 2004.
Usage
document.description
Description
Property; a string that is equivalent to the Description field in the Accessibility panel. The
description is read by the screen reader.
Example
The following example sets the description of the document:
fl.getDocumentDOM().description= "This is the main movie";
The following example gets the description of the document and displays it in the Output panel:
The following example distributes the selected objects by their top edges, using the bounds of the
document:
fl.getDocumentDOM().distribute("top edge", true);
document.distributeToLayers()
Availability
Flash MX 2004.
Usage
document.distributeToLayers()
Parameters
None.
Document object83
Returns
Nothing.
Description
Method; performs a distribute-to-layers operation on the current selection—equivalent to
selecting Distribute to Layers. This method displays an error if there is no selection.
Example
The following example distributes the current selection to layers:
fl.getDocumentDOM().distributeToLayers();
document.documentHasData()
Availability
Flash MX 2004.
Usage
document.documentHasData( name )
Parameters
name
A string that specifies the name of the data to check.
Returns
A Boolean value: true if the document has persistent data; false otherwise.
Description
Method; checks the document for persistent data with the specified name. See
document.addDataToDocument(), document.getDataFromDocument(), and
document.removeDataFromDocument().
Example
The following example checks the document for persistent data with the name "myData":
var hasData = fl.getDocumentDOM().documentHasData("myData");
"newWindow". If no parameter is specified, the default is symbol-editing mode. This parameter is
A string that specifies the editing mode. Valid values are "inPlace" or
optional.
86Chapter 3: Objects
Returns
Nothing.
Description
Method; switches the authoring tool into the editing mode specified by the parameter. If no
parameter is specified, the method defaults to symbol-editing mode, which has the same result as
right-clicking the symbol to invoke the context menu and selecting Edit. See
document.exitEditMode().
Example
The following example puts Flash in edit-in-place mode for the currently selected symbol:
fl.getDocumentDOM().enterEditMode('inPlace');
The following example puts Flash in edit-in-new-window mode for the currently selected symbol:
fl.getDocumentDOM().enterEditMode('newWindow');
document.exitEditMode()
Availability
Flash MX 2004.
Usage
document.exitEditMode()
Parameters
None.
Returns
Nothing.
Description
Method; exits from symbol-editing mode and returns focus to the next level up from the editing
mode. For example, if you are editing a symbol inside another symbol, this method takes you up
a level from the symbol you are editing, into the parent symbol. See
document.enterEditMode().
Example
The following example exits symbol-editing mode:
fl.getDocumentDOM().exitEditMode();
document.exportPublishProfile()
Availability
Flash MX 2004.
Usage
document.exportPublishProfile( fileURI )
Document object87
Parameters
fileURI
A string, expressed as a file://URL, that specifies the path of the XML file to which the
profile is exported.
Returns
Nothing.
Description
Method; exports the currently active profile to a file.
Example
The following example exports the currently active profile to the file named profile.xml in the
folder /Documents and Settings/username/Desktop on the C drive:
fl.getDocumentDOM().exportPublishProfile('file:///C|/Documents and Settings/
username/Desktop/profile.xml');
document.exportSWF()
Availability
Flash MX 2004.
Usage
document.exportSWF( [fileURI]
Parameters
fileURI
fileURI is empty or not specified, Flash displays the Export Movie dialog box. This parameter is
A string, expressed as a file://URL, that specifies the name of the exported file. If
{, bCurrentSettings] )
optional.
bCurrentSettings A Boolean value that, when set to true, causes Flash to use current SWF
publish settings. Otherwise, Flash displays the Export Flash Player dialog box. The default is
false. This parameter is optional.
Returns
Nothing.
Description
Method; exports the document to the specified file in the Flash SWF format.
Example
The following example exports the document to the specified file location with the current
publish settings:
fl.getDocumentDOM().exportSWF("file:///C|/Documents and Settings/gdrieu/
Desktop/qwerty.swf");
88Chapter 3: Objects
The following example displays the Export Movie dialog box and the Export Flash Player dialog
box and then exports the document based on the specified settings:
fl.getDocumentDOM().exportSWF("", true);
The following example displays the Export Movie dialog box and then exports the document with
specified settings:
fl.getDocumentDOM().exportSWF();
document.forceSimple
Availability
Flash MX 2004.
Usage
document.forceSimple
Description
Property; a Boolean value that specifies whether the children of the specified object are accessible.
This is equivalent to the inverse logic of the Make Child Objects Accessible setting in the
Accessibility panel. That is, if
Accessible option being unchecked. If
forceSimple is true, it is the same as the Make Child Object
forceSimple is false, it is the same as the Make Child
Object Accessible option being checked.
Example
The following example sets the areChildrenAccessible variable to the value of the
forceSimple property; a value of false means the children are accessible:
var areChildrenAccessible = fl.getDocumentDOM().forceSimple;
The following example sets the forceSimple property to allow the children of the document to
be accessible:
fl.getDocumentDOM().forceSimple = false;
document.frameRate
Availability
Flash MX 2004.
Usage
document.frameRate
Description
Property; a float value that specifies the number of frames displayed per second when the SWF
file plays; the default is 12. This is the same functionality as setting the frame rate in the
Document properties dialog box (Modify > Document).
Document object89
Example
The following example sets the frame rate to 25.5 frames per second:
fl.getDocumentDOM().frameRate = 25.5;
document.getAlignToDocument()
Availability
Flash MX 2004.
Usage
document.getAlignToDocument()
Parameters
None.
Returns
A Boolean value: true if the preference is set to align the objects to the Stage; false otherwise.
Description
Method; identical to retrieving the value of the To Stage button in the Align panel. Gets the
preference that can be used for
document.match(), and document.space() methods on the document. See
document.setAlignToDocument().
Example
document.align(), document.distribute(),
The following example retrieves the value of the To Stage button in the Align panel. If the return
value is
var isAlignToDoc = fl.getDocumentDOM().getAlignToDocument();
fl.getDocumentDOM().align("left", isAlignToDoc);
true, the To Stage button is active; otherwise, it is not.
document.getCustomFill()
Availability
Flash MX 2004.
Usage
document.getCustomFill( [ objectToFill ] )
Parameters
objectToFill
A string that specifies the location of the fill object. The following values are
valid:
• "toolbar", which returns the fill object of the toolbar and Property inspector
• "selection", which returns the fill object of the selection
If you omit this parameter, the default value is
returns
undefined. This parameter is optional.
90Chapter 3: Objects
"selection". If there is no selection, the method
Returns
The Fill object specified by the objectToFill parameter, if successful; otherwise, it returns
undefined.
Description
Method; retrieves the fill object of the selected shape or, if specified, of the toolbar and Property
inspector. See
Example
document.setCustomFill().
The following example gets the fill object of the selection and then changes the selection’s color to
white:
var fill = fl.getDocumentDOM().getCustomFill();
fill.color = '#FFFFFF';
fill.style = "solid";
fl.getDocumentDOM().setCustomFill(fill);
The following example returns the fill object of the toolbar and Property inspector and then
changes the color swatch to a linear gradient:
var fill = fl.getDocumentDOM().getCustomFill("toolbar");
fill.style = "linearGradient";
fill.colorArray = [ 0x00ff00, 0xff0000, 0x0000ff ];
fill.posArray = [0, 100, 200];
fl.getDocumentDOM().setCustomFill( fill );
document.getCustomStroke()
Availability
Flash MX 2004.
Usage
document.getCustomStroke( [locationOfStroke] )
Parameters
locationOfStroke
A string that specifies the location of the stroke object. The following values
are valid:
• "toolbar", which, if set, returns the stroke object of the toolbar and Property inspector.
• "selection", which, if set, returns the stroke object of the selection.
If you omit this parameter, it defaults to
undefined. This parameter is optional.
Returns
The Stroke object specified by the locationOfStroke parameter, if successful; otherwise, it
returns
undefined.
"selection". If there is no selection, it returns
Document object91
Description
Returns the stroke object of the selected shape or, if specified, of the toolbar and Property
inspector. See
Example
document.setCustomStroke().
The following example returns the current stroke settings of the selection and changes the stroke
thickness to 2:
var stroke = fl.getDocumentDOM().getCustomStroke("selection");
stroke.thickness = 2;
fl.getDocumentDOM().setCustomStroke(stroke);
The following example returns the current stroke settings of the toolbar and Property inspector
and sets the stroke color to red:
var stroke = fl.getDocumentDOM().getCustomStroke("toolbar");
stroke.color = "#FF0000";
fl.getDocumentDOM().setCustomStroke(stroke);
document.getDataFromDocument()
Availability
Flash MX 2004.
Usage
document.getDataFromDocument( name )
Parameters
name
A string that specifies the name of the data to return.
Returns
The specified data.
Description
Method; retrieves the value of the specified data. The type returned depends on the type of data
that was stored. See
document.removeDataFromDocument().
Example
document.addDataToDocument(), document.documentHasData(), and
The following example adds an integer value of 12 to the current document and uses this method
to display the value in the Output panel:
The name of the Element property for which to retrieve the value.
Returns
The value of the specified property. Returns null if the property is an indeterminate state, as
when multiple elements are selected with different property values. Returns
undefined if the
property is not a valid property of the selected element.
Description
Method; gets the specified Element property for the current selection. See “Property summary for
the Element object” on page 149 for a list of valid values. See
document.setElementProperty().
Example
The following example gets the name of the Element property for the current selection:
//elementName = the instance name of the selected object
var elementName = fl.getDocumentDOM().getElementProperty("name");
document.getElementTextAttr()
Availability
Flash MX 2004.
Usage
document.getElementTextAttr( attrName
Parameters
attrName
A string that specifies the name of the TextAttrs property to be returned. For a list
[, startIndex[, endIndex]] )
of property names and expected values, see “Property summary for the TextAttrs object”
on page 299.
startIndex An integer that specifies the index of first character, with 0 (zero) specifying the
first position. This parameter is optional.
endIndex An integer that specifies the index of last character. This parameter is optional.
Document object93
Returns
If one text field is selected, the property is returned if there is only one value used within the text.
Returns
undefined if there are several values used inside the text field. If several text fields are
selected, and all the text alignment values are equal, the method returns this value. If several text
fields are selected, but all the text alignment values are not equal, the method returns
undefined.
If the optional arguments are not passed, these rules apply to the range of text currently selected
or the whole text field if the text is not currently being edited. If only
startIndex is passed, the
property of the character to the right of the index is returned, if all the selected text objects match
values. If
characters from
Description
startIndex and endIndex are passed, the value returned reflects the entire range of
startIndex up to, but not including, endIndex.
Method; gets a specific TextAttrs property of the selected text objects. Selected objects that are
not text fields are ignored. For a list of property names and expected values, see “Property
summary for the TextAttrs object” on page 299. See
Example
document.setElementTextAttr().
The following example gets the size of the selected text fields:
fl.getDocumentDOM().getElementTextAttr("size");
The following example gets the color of the character at index 3 in the selected text fields:
The bounding rectangle of the current selection, or 0 if nothing is selected.
Description
Method; gets the bounding rectangle of the current selection. If a selection is non-rectangular, the
smallest rectangle encompassing the entire selection is returned. The rectangle is based on the
document space or, when in an edit mode, the registration point of the symbol being edited. See
document.setSelectionRect().
94Chapter 3: Objects
Example
The following example gets the bounding rectangle for the current selection and then displays its
properties:
endIndex An integer that is an index of last character to get. This parameter is optional.
Returns
An integer that is an index of first character to get. This parameter is optional.
A string that contains the selected text.
Description
Method; gets the currently selected text. If the optional parameters are not passed, the current text
selection is used. If text is not currently opened for editing, the whole text string is returned. If
only
startIndex is passed, the string starting at that index and ending at the end of the field is
returned. If
but not including,
startIndex and endIndex are passed, the string starting from startIndex up to,
endIndex is returned. See document.setTextString().
If there are several text fields selected, the concatenation of all the strings is returned.
Example
The following example gets the string in the selected text fields:
fl.getDocumentDOM().getTextString();
The following example gets the string at character index 5 in the selected text fields:
fl.getDocumentDOM().getTextString(5);
The following example gets the string from character index 2 up to, but not including, character
index 10:
fl.getDocumentDOM().getTextString(2, 10);
Document object95
document.getTimeline()
Availability
Flash MX 2004.
Usage
document.getTimeline()
Parameters
None.
Returns
The current Timeline object.
Description
Method; retrieves the current Timeline object in the document. The current Timeline can be the
current scene, the current symbol being edited, or the current screen. See
document.currentTimeline, document.timelines, and symbolItem.timeline.
Example
The following example gets the Timeline object and returns the number of frames in the longest
layer:
The following example gets the Timeline object and displays its name:
var timeline = fl.getDocumentDOM().getTimeline();
alert(timeline.name);
document.getTransformationPoint()
Availability
Flash MX 2004.
Usage
document.getTransformationPoint()
Parameters
None.
Returns
The location of the transformation point.
96Chapter 3: Objects
Description
Method; gets the location of the transformation point of the current selection. You can use the
transformation point for commutations such as rotate and skew. See
document.setTransformationPoint().
Example
The following example gets the transformation point for the current selection. The
transPoint.x property gives the x coordinate of the transformation point. The transPoint.y
property gives the y coordinate of the transformation point:
var transPoint = fl.getDocumentDOM().getTransformationPoint();
document.group()
Availability
Flash MX 2004.
Usage
document.group()
Parameters
None.
Returns
Nothing.
Description
Method; converts the current selection to a group. See document.unGroup().
Example
The following example converts the objects in the current selection to a group:
fl.getDocumentDOM().group();
document.height
Availability
Flash MX 2004.
Usage
document.height
Description
Property; an integer that specifies the height of the document (Stage) in pixels. See
document.width.
Document object97
Example
The following example sets the height of the Stage to 400 pixels:
fl.getDocumentDOM().height = 400;
document.importPublishProfile()
Availability
Flash MX 2004.
Usage
document.importPublishProfile( fileURI )
Parameters
fileURI
A string that specifies the path, expressed as a file://URL, of the XML file defining the
profile to import.
Returns
An integer that is the index of the imported profile in the profiles list. Returns -1 if the profile
cannot be imported.
Description
Method; imports a profile from a file.
Example
The following example imports the profile contained in the profile.xml file and displays its index
in the profiles list:
alert(fl.getDocumentDOM().importPublishProfile('file:///C|/Documents and
Settings/username/Desktop/profile.xml'));
document.importSWF()
Availability
Flash MX 2004.
Usage
document.importSWF( fileURI )
Parameters
fileURI
Returns
A string that specifies the URI, expressed as a file://URI, for the SWF file to import.
Nothing.
Description
Method; imports a SWF file into the document. Performs the same operation as using the Import
menu option to specify a SWF file.
98Chapter 3: Objects
Example
The following example imports the "mySwf.swf" file from the Flash Configuration folder:
Read-only property; the library object for a document.
Example
The following example gets the library for the currently focused document:
var myCurrentLib = fl.getDocumentDOM().library;
Assuming the currently focused document is not fl.documents[1], the following example gets
the library for a non-focused library or for a library you opened using File > Open as external
library:
var externalLib = fl.documents[1].library;
document.livePreview
Availability
Flash MX 2004.
Usage
document.livePreview
Description
Property; a Boolean value that specifies if Live Preview is enabled. If set to true, components
appear on the Stage as they will appear in the published Flash content, including their
approximate size. If set to
Example
false, components appear only as outlines. The default value is true.
A Boolean value that, when set to true, causes the method to make the widths of the
selected items the same.
bHeight A Boolean value that, when set to true, causes the method to make the heights of the
selected items the same.
bUseDocumentBounds A Boolean value that, when set to true, causes the method to match the
size of the objects to the bounds of the document. Otherwise, the method uses the bounds of the
largest object. The default is false. This parameter is optional.
Returns
Nothing.
Description
Method; makes the size of the selected objects the same. See document.setAlignToDocument()
and
document.getAlignToDocument().
Example
The following example matches the width of the selected objects only:
fl.getDocumentDOM().match(true,false);
The following example matches the height only:
fl.getDocumentDOM().match(false,true);
The following example matches the width only to the bounds of the document:
fl.getDocumentDOM().match(true,false,true);
document.mouseClick()
Availability
Flash MX 2004.
Usage
document.mouseClick( position
Parameters
position
A pair of floating point values that specify the x and y coordinates of the click in
pixels.
100Chapter 3: Objects
, bToggleSel, bShiftSel )
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.