If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is furnished under license and
may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored
in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe
Systems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an enduser license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe
Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informational
content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized
incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required
from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any actual organization.
Adobe, the Adobe logo, ActionScript, Dreamweaver, Fireworks, Flash, Flash Lite, and Version Cue are either registered trademarks or trademarks of Adobe
Systems Incorporated in the United States and/or other countries.
Windows and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries. Macintosh and
Mac OS are trademarks of Apple Inc., registered in the United States and other countries. All other trademarks are the property of their respective owners.
This product includes software developed by the Apache Software Foundation (http://www.apache.org/).
MPEG Layer-3 audio compression technology licensed by Fraunhofer IIS and Thomson Multimedia (http://www.mp3licensing.com).
Speech compression and decompression technology licensed from Nellymoser, Inc. (www.nellymoser.com).
This product includes software developed by the OpenSymphony Group (http://www.opensymphony.com/).
This product contains either BSAFE and/or TIPEM software by RSA Security, Inc.
Sorenson Spark™ video compression and decompression technology licensed from Sorenson Media, Inc.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA
Notice to U.S. government end users. The software and documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of
“Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202,
as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and
Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial items and (b) with only those rights
as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicable
equal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment
Assistance Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60,
60-250 ,and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference.
As a user of Adobe® Flash® CS4 Professional, you may be familiar with Adobe® ActionScript®, which lets you create
scripts that execute at run time in Adobe® Flash® Player. The Flash JavaScript application programming interface
(JavaScript API) described in this document is a complementary programming tool that lets you create scripts that run
in the authoring environment.
This document describes the objects, methods, and properties available in the JavaScript API. It assumes that you
know how to use the documented commands when working in the authoring environment. If you have a question
about what a particular command does, use other documents in Flash Help, such as Using Flash, to find that
information.
This document also assumes that you are familiar with JavaScript or ActionScript syntax and with basic programming
concepts such as functions, parameters, and data types.
Working with the JavaScript API
1
The Flash JavaScript API lets you write scripts to perform several actions in the Flash authoring environment (that is,
while a user has the Flash program open). This functionality is different from the ActionScript language, which lets
you write scripts to perform actions in the Flash Player environment (that is, while a SWF file is playing). This
functionality is also different from JavaScript commands that you might use in pages displayed in a web browser.
Using the JavaScript API, you can write Flash application scripts to help streamline the authoring process. For
example, you can write scripts to automate repetitive tasks or add custom tools to the Tools panel.
The Flash JavaScript API is designed to resemble the Adobe® Dreamweaver® and Adobe® Fireworks® JavaScript API
(which were designed based on the Netscape JavaScript API). The Flash JavaScript API is based on a Document Object
Model (DOM), which allows Flash documents to be accessed using JavaScript objects. The Flash JavaScript API
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 have an effect.
The JavaScript API also contains methods that let you implement extensibility using a combination of JavaScript and
custom C code. For more information, see
The JavaScript interpreter in Flash is the Mozilla SpiderMonkey engine, version 1.5, which is available on the web at
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 core JavaScript language as defined in the ECMAScript (ECMA-262) edition 3
language specification and it is fully compliant with the specification. Only the browser-specific host objects, which
are not part of the ECMA-262 specification, are not supported. Similarly, many JavaScript reference guides distinguish
between core JavaScript and client-side (browser-related) JavaScript. Only core JavaScript applies to the Flash
JavaScript interpreter.
“C-Level Extensibility” on page 522.
Creating JSFL files
You can use Adobe Flash CS4 Professional or your preferred text editor to write and edit Flash JavaScript (JSFL) files.
If you use Flash, these files have a .jsfl extension by default. To write a script, select File
> New > Flash JavaScript File.
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
You can also create a JSFL file by selecting commands in the History panel. Then click the Save button in the History
panel or select Save As Command from the panel menu. The command (JSFL) file is saved in the Commands folder
“Saving JSFL files” on page 2). You can then open the file and edit it the same as any other script file.
(see
The History panel provides some other useful options as well. You can copy selected commands to the Clipboard, and
you can view JavaScript commands that are generated while you are working in Flash.
To copy commands from the History panel to the clipboard:
1 Select one or more commands in the History panel.
2 Do one of the following:
• Click the Copy button.
• Select Copy Steps from the panel menu.
To view JavaScript commands in the History panel:
• Select View > JavaScript in Panel from the panel menu.
Saving JSFL files
You can have JSFL scripts available within the Flash authoring environment by storing them in one of several folders
within the Configuration folder. By default, the Configuration folder is in the following location:
boot drive\Documents and Settings\username\Local Settings\Application Data\Adobe\Flash
CS4\language\Configuration\
• Mac OS® X:
Macintosh HD/Users/username/Library/Application Support/Adobe/Flash CS4/language/Configuration/
To determine the location of the Configuration folder, use fl.configDirectory or fl.configURI, as shown in the
following example:
// store directory to a variable
var configDir = fl.configDirectory;
// display directory in the Output panel
fl.trace(fl.configDirectory);
Within the Configuration folder, the following folders can contain scripts that you can access in the authoring
environment: Behaviors (to support the user interface for behaviors); Commands (for scripts that appear on the
Commands menu); JavaScript (for scripts used by Script Assist to populate the user interface controls); Tools (for
extensible tools in the Tools panel); and WindowSWF (for panels that appear in the Windows menu). This document
focuses on scripts used for commands and tools.
If you edit a script in the Commands folder, the new script is immediately available in Flash. If you edit a script for an
extensible tool, close and restart Flash, or else use the
fl.reloadTools() command. However, if you used a script to
add an extensible tool to the Tools panel and you then edit the script, either remove and then add the tool to the Tools
panel again, or else close and restart Flash for the revised tool to be available.
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
There are two locations where you can store command and tool files so they can be accessed in the authoring
environment.
• For scripts that appear as items in the Commands menu, save the JSFL file in the Commands folder in the following
location:
Operating systemLocation
3
Windows Vistaboot drive\Users\username\Local Settings\Application Data\Adobe\Flash
Windows XPboot drive\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash
Mac OS XMacintosh HD/Users/userName/Library/Application Support/Adobe/Flash
CS4\language\Configuration\Commands
CS4\language\Configuration\Commands
CS4/language/Configuration/Commands
• For scripts that appear as extensible tools in the Tools panel, save the JSFL file in the Tools folder in the following
location:
Operating systemLocation
Windows Vistaboot drive\Users\username\Local Settings\Application Data\Adobe\Flash
Windows XPboot drive\Documents and Settings\user\Local Settings\Application Data\Adobe\Flash
Mac OS XMacintosh HD/Users/userName/Library/Application Support/Adobe/Flash
CS4\language\Configuration\Tools
CS4\language\Configuration\Tools
CS4/language/Configuration/Tools
If a JSFL file has other files that go with it, such as XML files, store them in the same directory as the JSFL file.
Running scripts
There are several ways to run scripts. The most common ways are explained in this section.
To run a script that you are currently viewing or editing:
• Right-click (Command-click on the Macintosh) and choose Run Script.
• Click the Run Script icon on the Script window toolbar.
This option lets you run a script before you have saved it. This option also lets you run a script even if no FLA files are open.
To run a script that is in the Commands folder, do one of the following:
• From the authoring environment, select Commands > Script Name.
• Use a keyboard shortcut that you have assigned to the script. To assign a keyboard shortcut, use Edit > Keyboard
Shortcuts and select Drawing Menu Commands from the Commands pop-up menu. Expand the Commands node
in the menu tree to view a list of available scripts.
To run a command script that is not in the Commands folder, do one of the following:
• From the authoring environment, select Commands > Run Command, and then select the script to run.
• From within a script, use the fl.runScript() command.
• From the file system, double-click the script file.
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
To add a tool implemented in a JSFL file to the Tools panel:
1 Copy the JSFL file for the tool and any other associated files to the Tools folder (see “Saving JSFL files” on page 2).
You can add individual JavaScript API commands to ActionScript files by using the MMExecute() function, which is
documented in the ActionScript 3.0 Language and Components Reference. However, the
MMExecute() function 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, JavaScript API commands have
no effect in Flash Player or outside the authoring environment.
To issue a command from an ActionScript script:
• Use the following syntax (you can concatenate several commands into one string):
MMExecute(Javascript command string);
You can also run a script from the command line.
To run a script from the command line on Windows:
• Use the following syntax (add path information as required):
"flash.exe" myTestFile.jsfl
4
To run a script from the “Terminal” application on the Macintosh:
• Use the following syntax (add path information as required):
osascript -e 'tell application "flash" to open alias "Mac OS X:Users:user:myTestFile.jsfl" '
The osascript command can also run AppleScript in a file. For example, you could include the following text in
a file named myScript:
tell application "flash"
open alias "Mac OS X:Users:user:myTestFile.jsfl"
end tell
Then, to run the script, you would use this command:
osascript myScript
What’s new in the JavaScript API
In Flash CS4, some objects, methods, and properties have been added while others have been removed. These changes
are summarized below.
If you have not used the JavaScript API before, you might want to skip this section and go directly to “JavaScript API
objects” on page 7).
New objects
The following objects are new in Flash CS4:
presetPanel object
presetItem object
swfPanel object
New methods and properties
The following methods and properties for existing objects are new in Flash CS4:
• BitmapItem object
• bitmapItem.exportToFile()
• bitmapItem.fileLastModifiedDate
• bitmapItem.originalCompressionType
• bitmapItem.sourceFileExists
• bitmapItem.sourceFileIsCurrent
• bitmapItem.sourceFilePath
• bitmapItem.useDeblocking
• Contour object
• contour.fill
• Document object
• document.addNewPrimitiveOval()
• document.addNewPrimitiveRectangle()
• document.exportPublishProfileString()
• document.externalLibraryPath
• document.importPublishProfileString()
• document.libraryPath
• document.pathURI
• document.rotate3DSelection
• document.setStageVanishingPoint()
• document.setStageViewAngle()
• document.sourcePath
• document.translate3DCenter()
• document.translate3DSelection()
• Edge object
• edge.cubicSegmentIndex
• edge.stroke
• Fill object
• fill.bitmapIsClipped
• fill.bitmapPath
• flash object (fl)
• fl.externalLibraryPath
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
5
• fl.flexSDKPath
• fl.isFontInstalled()
• fl.libraryPath
• fl.presetPanel
• fl.sourcePath
• fl.swfPanels
• FLfile object
• FLfile.platformPathToURI()
• FLfile.uriToPlatformPath()
• fontItem object
• fontItem.bitmap
• fontItem.bold
• fontItem.font
• fontItem.italic
• fontItem.size
• Shape object
• shape.getCubicSegmentPoints()
• shape.members
• shape.numCubicSegments
• SoundItem object
• soundItem.exportToFile()
• soundItem.fileLastModifiedDate
• soundItem.originalCompressionType
• soundItem.sourceFileExists
• soundItem.sourceFileIsCurrent
• soundItem.sourceFilePath
• Timeline object
• timeline.getGuidelines()
• timeline.setGuidelines()
• VideoItem object
• videoItem.exportToFLV()
• videoItem.fileLastModifiedDate
• videoItem.sourceFileExists
• videoItem.sourceFileIsCurrent
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
6
Other changes
The following property has a new supported value in Flash CS4:
• fill.style
The following objects, methods, and properties are no longer available in Flash CS4:
• Project object
• ProjectItem object
• fl.openProject()
• fl.closeProject()
• fl.createProject()
• fl.getProject()
• Effect object
• configureEffect()
• executeEffect()
• removeEffect()
• fl.activeEffect
• fl.effects
• fl.enableImmediateUpdates()
• fl.reloadEffects()
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
7
JavaScript API objects
This section provides a summary of the objects available in the Flash JavaScript API and how to begin working with
them. All standard JavaScript commands are also available when working with the JavaScript API.
The following table briefly describes each of the objects in the JavaScript API. The objects are listed in alphabetical
order.
ObjectDescription
actionsPanel objectThe actionsPanel object represents the currently displayed Actions panel.
BitmapInstance object The BitmapInstance object is a subclass of the Instance object and represents
BitmapItem object A BitmapItem object refers to a bitmap in the library of a document. The
CompiledClipInstance object The CompiledClipInstance object is a subclass of the Instance object.
compilerErrors objectThe compilerErrors object represents the Compiler Errors panel. It is a
ComponentInstance objectThe ComponentInstance object is a subclass of the SymbolInstance object
componentsPanel objectThe componentsPanel object, which represents the Components panel, is a
a bitmap in a frame.
BitmapItem object is a subclass of the Item object.
property of the flash object (fl.compilerErrors).
and represents a component in a frame.
property of the flash object (
fl.componentsPanel).
ObjectDescription
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
8
Contour objectA Contour object represents a closed path of half edges on the boundary of
a shape.
Document objectThe Document object represents the Stage.
drawingLayer objectThe drawingLayer object is accessible from JavaScript as a child of the flash
object.
Edge objectThe Edge object represents an edge of a shape on the Stage.
Element objectEverything that appears on the Stage is of the type Element.
Fill objectThe Fill object contains all the properties of the Fill color setting of the Tools
panel or of a selected shape.
Filter objectThe Filter object contains all the properties for all filters.
flash object (fl)The flash object represents the Flash application.
FLfile objectThe FLfile object lets you write Flash extensions that can access, modify, and
remove files and folders on the local file system.
folderItem objectThe folderItem object is a subclass of the Item object.
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.
Math objectThe Math object is available as a read-only property of the flash object
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. It is a property of the flash
fl.outputPanel).
object (
Oval objectThe Oval object is a shape that is drawn using the Oval tool. To determine if
an item is an Oval object, use
shape.isOvalObject.
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.
presetItem objectThe presetItem object represents an item (preset or folder) in the Motion
Motion Presets). It is a property of the flash object (
fl.presetPanel).
ObjectDescription
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
9
Rectangle objectThe Rectangle object is a shape that is drawn using the Rectangle tool. To
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
Shape objectThe Shape object is a subclass of the Element object. The Shape object
SoundItem objectThe SoundItem object is a subclass of the Item object. It represents a library
Stroke objectThe Stroke object contains all the settings for a stroke, including the custom
swfPanel objectThe swfPanel object represents a Windows SWF panel. Windows SWF panels
SymbolInstance objectThe SymbolInstance object is a subclass of the Instance object and represents
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
determine if an item is a Rectangle object, use
shape.isRectangleObject.
document.
provides more precise control than the drawing APIs for manipulating or
creating geometry on the Stage.
item used to create a sound.
settings.
are SWF files that implement applications you can run from the Flash
authoring environment. The array of swfPanel objects is a property of the
flash object (
a symbol in a frame.
a subselection. This object is a subclass of the Text object.
fl.swfPanels).
TextRun objectThe TextRun object represents a run of characters that have attributes that
Timeline objectThe Timeline object represents the Flash timeline, which can be accessed for
ToolObj objectA ToolObj object represents an individual tool in the Tools panel.
Tools objectThe Tools object is accessible from the Flash object (fl.tools).
Vertex objectThe Vertex object is the part of the shape data structure that holds the
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 XMLUI
match all of the properties in the TextAttrs object.
the current document by
coordinate data.
dialog box, and accept or cancel out of one.
fl.getDocumentDOM().getTimeline().
The Flash Document Object Model
The Flash Document Object Model (DOM) for the Flash JavaScript API consists of a set of top-level functions (see
“Top-Level Functions and Methods” on page 15) and two top-level objects—the FLfile object and the flash object (fl).
Each object is guaranteed to be available to a script because it always exists when the Flash authoring environment is
open. For more information, see
When referring to the flash object, you can use flash or fl. For example, to close all open FLA files, you can use either
of the following statements:
FLfile object and flash object (fl).
flash.closeAll();
fl.closeAll();
The flash object contains the following child objects:
ObjectHow to access
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
10
actionsPanel objectUse fl.actionsPanel to access the actionsPanel object. This object corresponds
compilerErrors objectUse fl.compilerErrors to access the compilerErrors object. This object
componentsPanel objectUse fl.componentsPanel to access the componentsPanel object. This object
Document objectUse fl.documents to retrieve an array of all the open documents; use
drawingLayer objectUse fl.drawingLayer to access the drawingLayer object.
Math objectUse fl.Math to access the Math object.
outputPanel objectUse fl.outputPanel to access the outputPanel object. This object corresponds to
presetPanel objectUse fl.presetPanel to access the presetPanel object. This object corresponds to
swfPanel objectUse fl.swfPanels to access an array of swfPanel objects. These objects
Tools objectUse fl.tools to access an array of Tools objects.
XMLUI objectUse fl.xmlui to access an XML User Interface (XMLUI) object. The XMLUI object
to the Actions panel in the Flash authoring environment.
corresponds to the Compiler Errors panel in the Flash authoring environment.
corresponds to the Components panel in the Flash authoring environment.
fl.documents[index] to access a particular document; use
fl.getDocumentDOM() to access the current document (the one with focus).
the Output panel in the Flash authoring environment.
the Motion Presets panel (Window
correspond to Window SWF panels.
provides the ability to get and set properties of an XMLUI dialog box.
> Motion Presets).
The Document object
An important property of the top-level flash object is the fl.documents property. This property contains an array of
Document objects, each of which represents 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 Document object. For more information, see
Document object.
To refer to the first open document, for example, use the statement flash.documents[0] or fl.documents[0]. The
first document is the first Flash document that was opened during the 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 flash.findDocumentIndex(nameOfDocument) or
fl.findDocumentIndex(nameOfDocument). See fl.findDocumentIndex().
To access the document that is currently focused, use the statement flash.getDocumentDOM() or
fl.getDocumentDOM(). See fl.getDocumentDOM(). 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. See fl.documents and document.name.
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.itemslibrary.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);
11
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.
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
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.
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 parent object
(the superclass). Subclasses share the same level in the hierarchy as their superclass. For example, the Item object is a
superclass of the BitmapItem object. These relationships are illustrated in the following outline:
Several sample JSFL implementations are available for Adobe Flash CS4 Professional. You can review and install these
files to familiarize yourself with the JavaScript API. The samples are in a folder named Samples/ExtendingFlash within
the Samples.zip file located at
Sample Shape command
A sample JavaScript API script named Shape.jsfl is located in the ExtendingFlash/Shape folder (see “Sample
implementations” above). This script displays information about the contours of the shape in the Output panel.
To install and run the Shape script:
1 Copy the Shape.jsfl file to the Configuration/Commands folder (see “Saving JSFL files” on page 2).
2 In a Flash document (FLA file), select a shape object.
3 Select Commands > Shape to run the script.
Sample get and set filters command
A sample JavaScript API script named filtersGetSet.jsfl is located in the ExtendingFlash/filtersGetSet folder (see
“Sample implementations” above). This script adds filters to a selected object and displays information about the filters
being added in the Output panel.
To install and run the filtersGetSet script:
1 Copy the filtersGetSet.jsfl file to the Configuration/Commands folder (see “Saving JSFL files” on page 2).
2 In a Flash document (FLA file), select a text, movie clip, or button object.
3 Select Commands > filtersGetSet to run the script.
www.adobe.com/go/learn_fl_samples.
EXTENDING FLASH CS4 PROFESSIONAL
Introduction
Sample PolyStar tool
A sample JavaScript API script named PolyStar.jsfl is located in the ExtendingFlash/PolyStar folder (see “Sample
implementations” above).
The PolyStar.jsfl replicates the PolyStar tool that can be found in the Flash Tools panel. The script demonstrates how
to build the PolyStar tool using the JavaScript API and includes detailed comments describing what the code is doing.
Read this file to gain a better understanding of how the JavaScript API can be used. You should also read the
PolyStar.xml file in the Tools directory to learn more about how to build your own tool.
Sample Trace Bitmap panel
A set of files named TraceBitmap.fla and TraceBitmap.swf are located in the ExtendingFlash/TraceBitmapPanel folder
(see “Sample implementations” above). These files illustrate how to design and build a panel to control the functions
of Flash. They also show the use of the
script.
To run the TraceBitmap sample:
1 If Flash is running, exit from Flash.
2 Copy the TraceBitmap.swf file to the WindowSWF folder, which is a subdirectory of the Configuration folder (see
“Saving JSFL files” on page 2). For example, on Windows XP, the folder is in boot drive\Documents and
Settings\user\Local Settings\Application Data\Adobe\Flash CS4\language\Configuration\WindowSWF.
3 Start Flash.
4 Create or open a Flash document (FLA file), and import a bitmap or JPEG image into the file.
You can use the flower.jpg file provided in the TraceBitmapPanel folder or another image of your choice.
MMExecute() function to call JavaScript commands from an ActionScript
14
5 With the imported image selected, select Window > Other Panels > TraceBitmap.
6 Click Submit.
The image is converted into a group of shapes.
Sample DLL
A sample DLL implementation is located in the ExtendingFlash/dllSampleComputeSum folder (see “Sample
implementations” above). For more information about building DLLs, see
“C-Level Extensibility” on page 522.
Chapter 2: Top-Level Functions and
Methods
About this section
This section describes the top-level functions and methods that are available when you use the Adobe Flash JavaScript
application programming interface (JavaScript API). For information about where to store JavaScript API files, see
“Saving JSFL files” on page 2.
Global methods
The following methods can be called from any JavaScript API script:
alert()
confirm()
prompt()
Extensible tools
The following functions are available in scripts that create extensible tools:
Function; called when the extensible tool becomes active (that is, when the tool is selected in the Tools panel). Use this
function to perform any initialization tasks the tool requires.
Example
The following example sets the value of tools.activeTool when the extensible tool is selected in the Tools panel:
function activate() {
var theTool = fl.tools.activeTool
}
See also
tools.activeTool
alert()
Availability
Flash MX 2004.
16
Usage
alert ( alertText )
Parameters
alertText A string that specifies the message you want to display in the Alert dialog box.
Returns
Nothing.
Description
Method; displays a string in a modal Alert dialog box, along with an OK button.
Example
The following example displays the message “Process Complete” in an Alert dialog box:
alert("Process Complete");
See also
confirm(), prompt()
configureTool()
Availability
Flash MX 2004.
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
Usage
function configureTool() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
Function; called when Flash opens and the extensible tool is loaded into the Tools panel. 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:
function configureTool() {
theTool = fl.tools.activeTool;
theTool.setToolName("myTool");
theTool.setIcon("myTool.png");
theTool.setMenuString("My Tool's menu string");
theTool.setToolTip("my tool's tool tip");
theTool.setOptionsFile( "mtTool.xml" );
}
strAlert A string that specifies the message you want to display in the Alert dialog box.
Returns
A Boolean value: true if the user clicks OK; false if the user clicks Cancel.
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
Description
Method; displays a string in a modal Alert dialog box, along with OK and Cancel buttons.
Note: If there are no documents (FLA files) open, this method fails with an error condition.
Example
The following example displays the message “Sort data?” in an Alert dialog box:
confirm("Sort data?");
See also
alert(), prompt()
deactivate()
Availability
Flash MX 2004.
18
Usage
function deactivate() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
Function; called when the extensible 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
The following example displays a message in the Output panel when the tool becomes inactive:
function deactivate() {
fl.trace( "Tool is no longer active" );
}
keyDown()
Availability
Flash MX 2004.
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
Usage
function keyDown() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
Function; called when the extensible tool is active and the user presses a key. The script should call
tools.getKeyDown() to determine which key was pressed.
Example
The following example displays information about which key was pressed when the extensible tool is active and the
user presses a key.
function keyDown() {
fl.trace("key " + fl.tools.getKeyDown() + " was pressed");
}
19
See also
keyUp(), tools.getKeyDown()
keyUp()
Availability
Flash MX 2004.
Usage
function keyUp() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
Function; called when the extensible tool is active and a key is released.
Example
The following example displays a message in the Output panel when the extensible tool is active and a key is released.
function keyUp() {
fl.trace("Key is released");
}
See also
keyDown()
mouseDoubleClick()
Availability
Flash MX 2004.
Usage
function mouseDoubleClick() {
// statements
}
Parameters
None.
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
20
Returns
Nothing.
Description
Function; called when the extensible tool is active and the mouse button is double-clicked on the Stage.
Example
The following example displays a message in the Output panel when the extensible tool is active and the mouse button
is double-clicked.
function mouseDoubleClick() {
fl.trace("Mouse was double-clicked");
}
mouseDown()
Availability
Flash MX 2004.
Usage
function mouseDown( [ pt ] ) {
// statements
}
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
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
Function; called when the extensible tool is active and the mouse button is pressed while the pointer is over the Stage.
Example
The following examples show how this function can be used when the extensible tool is active. The first example
displays a message in the Output panel that the mouse button was pressed. The second example displays the x and y
coordinates of the mouse’s location when the button was pressed.
function mouseDown() {
fl.trace("Mouse button has been pressed");
}
function mouseDown(pt) {
fl.trace("x = "+ pt.x+" :: y = "+pt.y);
}
21
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
Function; called whenever the extensible tool is active and the mouse moves over a specified point on the Stage. The
mouse button can be down or up.
Example
The following examples show how this function can be used. The first example displays a message in the Output panel
that the mouse is being moved. The second example displays the x and y coordinates of the mouse’s location as it
moves.
function mouseMove() {
fl.trace("moving");
}
function mouseMove(pt) {
fl.trace("x = "+ pt.x + " :: y = " + pt.y);
}
mouseUp()
Availability
Flash MX 2004.
Usage
function mouseUp() {
// statements
}
Parameters
None.
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
22
Returns
Nothing.
Description
Function; called whenever the extensible tool is active and the mouse button is released after being pressed on the
Stage.
Example
The following example displays a message in the Output panel when the extensible tool is active and the mouse button
is released.
function mouseUp() {
fl.trace("mouse is up");
}
notifySettingsChanged()
Availability
Flash MX 2004.
Usage
function notifySettingsChanged() {
// statements
}
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
Parameters
None.
Returns
Nothing.
Description
Function; called when the extensible tool is active and the user changes its options in the Property inspector. You can
tools.activeTool property to query the current values of the options (see tools.activeTool).
use the
Example
The following example displays a message in the Output panel when the extensible tool is active and the user changes
its options in the Property inspector.
function notifySettingsChanged() {
var theTool = fl.tools.activeTool;
var newValue = theTool.myProp;
}
23
prompt()
Availability
Flash MX 2004.
Usage
prompt(promptMsg [,text])
Parameters
promptMsg A string to display in the Prompt dialog box (limited to 256 characters in Mac OS X).
text An optional string to display as a default value for the text field.
Returns
The string the user typed if the user clicks OK; null if the user clicks Cancel.
Description
Method; displays a prompt and optional text in a modal Alert dialog box, along with OK and Cancel buttons.
Example
The following example prompts the user to enter a user name. If the user types a name and clicks OK, the name appears
in the Output panel.
var userName = prompt("Enter user name", "Type user name here");
fl.trace(userName);
See also
alert(), confirm()
EXTENDING FLASH CS4 PROFESSIONAL
Top-Level Functions and Methods
setCursor()
Availability
Flash MX 2004.
Usage
function setCursor() {
// statements
}
Parameters
None.
Returns
Nothing.
Description
Function; called when the extensible tool is active and the mouse moves, to allow the script to set custom pointers. The
script should call
to which integer values, see
tools.setCursor() to specify the pointer to use. For a list that shows which pointers correspond
tools.setCursor().
24
Example
function setCursor() {
fl.tools.setCursor( 1 );
}
Chapter 3: actionsPanel object
Availability
Flash CS3 Professional.
Description
The actionsPanel object, which represents the currently displayed Actions panel, is a property of the flash object (see
fl.actionsPanel).
Method summary
The following methods can be used with the actionsPanel object:
MethodDescription
actionsPanel.getClassForObject()Returns the class of a specified variable.
actionsPanel.getScriptAssistMode()Specifies whether Script Assist mode is enabled.
actionsPanel.getSelectedText()Returns the text that is currently selected in the Actions panel.
25
actionsPanel.getText()Returns the text in the Actions panel.
actionsPanel.hasSelection()Specifies whether any text is currently selected in the Actions panel.
actionsPanel.replaceSelectedText()Replaces the currently selected text with specified text.
actionsPanel.setScriptAssistMode()Enables or disables Script Assist mode.
actionsPanel.setSelection()Selects a specified set of characters in the Actions panel.
actionsPanel.setText()Clears any text in the Actions panel and then adds specified text.
actionsPanel.getClassForObject()
Availability
Flash CS3 Professional.
Usage
actionsPanel.getClassForObject(ASvariableName)
Parameters
ASvariableName A string that represents the name of an ActionScript variable.
Returns
A string that represents the class of which ASvariableName is a member.
Description
Method; returns the class of the specified variable, which must be defined in the currently displayed Actions panel. In
addition, the cursor or selected text in the Actions panel must be positioned after the variable definition.
EXTENDING FLASH CS4 PROFESSIONAL
actionsPanel object
Example
The following example displays the class assigned to the variable myVar, if the cursor is positioned after the statement
var myVar:ActivityEvent; in the Actions panel.
// Place the following code in the Actions panel,
// and position the cursor somewhere after the end of the line
var myVar:ActivityEvent;
// Place the following code in the JSFL file
var theClass = fl.actionsPanel.getClassForObject("myVar");
fl.trace(theClass); // traces: "ActivityEvent"
actionsPanel.getScriptAssistMode()
Availability
Flash CS3 Professional.
Usage
actionsPanel.getScriptAssistMode()
26
Parameters
None.
Returns
A Boolean value that specifies whether Script Assist mode is enabled (true) or not (false).
Description
Method; specifies whether Script Assist mode is enabled.
Example
The following example displays a message if Script Assist mode is not enabled.
mAssist = fl.actionsPanel.getScriptAssistMode();
if (!mAssist) {
alert("For more guidance when writing ActionScript code, try Script Assist mode");
}
See also
actionsPanel.setScriptAssistMode()
actionsPanel.getSelectedText()
Availability
Flash CS3 Professional.
Usage
actionsPanel.getSelectedText()
EXTENDING FLASH CS4 PROFESSIONAL
actionsPanel object
Parameters
None.
Returns
A string that contains the text that is currently selected in the Actions panel.
Description
Method; returns the text that is currently selected in the Actions panel.
Example
The following example displays the text that is currently selected in the Actions panel.
var apText = fl.actionsPanel.getSelectedText();
fl.trace(apText);
A Boolean value that specifies whether any text is selected in the Actions panel (true) or not (false).
Description
Method; specifies whether any text is currently selected in the Actions panel.
Example
The following example displays text that is currently selected in the Actions panel. If no text is selected, it displays all
the text in the Actions panel.
28
if (fl.actionsPanel.hasSelection()) {
var apText = fl.actionsPanel.getSelectedText();
}
else {
var apText = fl.actionsPanel.getText();
}
fl.trace(apText);
replacementText A string that represents text to replace selected text in the Actions panel.
Returns
A Boolean value of true if the Actions panel is found; false otherwise.
EXTENDING FLASH CS4 PROFESSIONAL
actionsPanel object
Description
Method; replaces the currently selected text with the text specified in replacementText. If replacementText contains
more characters than the selected text, any characters following the selected text now follow replacementText; that is,
they are not overwritten.
Example
The following example replaces currently selected text in the Actions panel.
startIndex A zero-based integer that specifies the first character to be selected.
numberOfChars An integer that specifies how many characters to select.
Returns
A Boolean value that specifies whether the requested characters can be selected (true) or not (false).
Description
Method; selects a specified set of characters in the Actions panel.
30
Example
The following example replaces the characters “2006” in the Actions panel with the specified text.
// Type the following as the first line in the Actions panel
// 2006 - Addresses user request 40196
// Type the following in the JSFL file
fl.actionsPanel.setSelection(3,4);
fl.actionsPanel.replaceSelectedText("// Last updated: 2007");
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 (see Instance object).
Method summary
In addition to the Instance object methods, you can use the following methods with the BitmapInstance object:
MethodDescription
32
bitmapInstance.getBits()Lets you create bitmap effects by getting the bits out of the bitmap,
bitmapInstance.setBits()Sets the bits of an existing bitmap element.
Property summary
In addition to the Instance object properties, you can use the following properties with the BitmapInstance object:
PropertyDescription
bitmapInstance.hPixelsRead-only; an integer that represents the width of the bitmap, in pixels.
bitmapInstance.vPixelsRead-only; an integer that represents the height of the bitmap, in pixels.
manipulating them, and then returning them to Flash.
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 bits
element is an array of bytes. The
array is the length of the color table.
cTab element is an array of color values of the form "#RRGGBB". The length of the
EXTENDING FLASH CS4 PROFESSIONAL
BitmapInstance object
The byte array is meaningful only when referenced by a DLL or shared library. You typically use it only when creating
an extensible tool or effect. For information on creating DLLs for use with Flash JavaScript, see
“C-Level Extensibility”
on page 522
Description
Method; lets you create bitmap effects by getting the bits out of the bitmap, manipulating them, and then returning
them to Flash.
Example
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:
Read-only property; an integer that represents the width of the bitmap—that is, the number of pixels in the horizontal
dimension.
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];
var isBitmap = bmObj.instanceType;
if(isBitmap == "bitmap"){
var numHorizontalPixels = bmObj.hPixels;
}
See also
bitmapInstance.vPixels
EXTENDING FLASH CS4 PROFESSIONAL
BitmapInstance object
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
depth of 8 or less and is a string that represents a color value in the form "#RRGGBB".
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
Nothing.
bits property is a byte array. The cTab property is required only for bitmaps with a bit
34
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 sets the height of the bitmap to 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);
}
See also
bitmapInstance.getBits()
bitmapInstance.vPixels
Availability
Flash MX 2004.
Usage
bitmapInstance.vPixels
Description
Read-only property; an integer that represents the height of the bitmap—that is, the number of pixels in the vertical
dimension.
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;
}
See also
bitmapInstance.hPixels
EXTENDING FLASH CS4 PROFESSIONAL
BitmapInstance object
35
Chapter 5: 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 (see Item object).
Property summary
In addition to the Item object properties, the BitmapItem object has following properties:
PropertyDescription
36
bitmapItem.allowSmoothingA Boolean value that specifies whether to allow smoothing
bitmapItem.compressionTypeA string that determines the type of image compression
bitmapItem.fileLastModifiedDateThe number of seconds that have elapsed between
bitmapItem.originalCompressionTypeSpecifies whether the item was imported as an jpeg file.
bitmapItem.sourceFileExistsSpecifies whether the file that was imported to the Library
bitmapItem.sourceFileIsCurrentSpecifies whether the file modification date of the Library
bitmapItem.sourceFilePathThe path and name of the file that was imported into the
bitmapItem.useDeblocking Specifies whether deblocking is enabled.
bitmapItem.useImportedJPEGQualityA Boolean value that specifies whether to use the default
of a bitmap.
applied to the bitmap.
January 1, 1970 and the modification date of the original
file.
still exists in the location from where it was imported.
item is the same as the modification date on disk of the file
that was imported.
Library.
imported JPEG quality.
Method summary
In addition to the Item object properties, the BitmapItem object has following methods:
MethodDescription
bitmapItem.exportToFile()Exports the specified item to a PNG or JPG file.
EXTENDING FLASH CS4 PROFESSIONAL
BitmapItem object
bitmapItem.allowSmoothing
Availability
Flash MX 2004.
Usage
bitmapItem.allowSmoothing
Description
Property; a Boolean value that specifies whether to allow smoothing of a bitmap (true) or not (false).
Example
The following code sets the allowSmoothing property of the first item in the library of the current document to true:
bitmapItem.useImportedJPEGQuality is true, "photo" corresponds to JPEG using the
"lossless" corresponds to GIF or PNG format (see
bitmapItem.exportToFile()
Availability
Flash CS4 Professional.
Usage
bitmapItem.exportToFile(fileURI)
EXTENDING FLASH CS4 PROFESSIONAL
Parameters
fileURI A string, expressed as a file:/// URI, that specifies the path and name of the exported file.
Returns
A Boolean value of true if the file was exported successfully; false otherwise.
Description
Method; exports the specified item to a PNG or JPG file.
Example
Assuming the first item in the Library is a bitmap item, the following code exports it as a JPG file:
var imageFileURL = "file:///C|/exportTest/out.jpg";
var libItem = fl.getDocumentDOM().library.items[0];
libItem.exportToFile(imageFileURL);
bitmapItem.fileLastModifiedDate
38
BitmapItem object
Availability
Flash CS4 Professional.
Usage
bitmapItem.fileLastModifiedDate
Description
Read-only property; a string containing a hexadecimal number that represents the number of seconds that have
elapsed between January 1, 1970 and the modification date of the original file at the time the file was imported to the
library. If the file no longer exists, this value is "00000000".
Example
Assuming the first item in the Library is a bitmap item, the following code displays a hex number as described above.
var libItem = fl.getDocumentDOM().library.items[0];
fl.trace("Mod date when imported = " + libItem.fileLastModifiedDate);
Read-only property; a string that specifies whether the specified item was imported as an jpeg file. Possible values for
this property are “photo” (for jpeg files) and “lossless” (for uncompressed file types such as GIF and PNG).
Example
Assuming that the first item in the Library is a bitmap item, the following code displays "photo" if the file was imported
into the Library as a jpeg file, or "lossless" if is was not:
var libItem = fl.getDocumentDOM().library.items[0];
fl.trace("Imported compression type = "+ libItem.originalCompressionType);
See also
bitmapItem.compressionType
bitmapItem.quality
Availability
Flash MX 2004.
39
Usage
bitmapItem.quality
Description
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:
Read-only property; a Boolean value of true if the file that was imported to the Library still exists in the location from
where it was imported;
false otherwise.
EXTENDING FLASH CS4 PROFESSIONAL
BitmapItem object
Example
Assuming the first item in the Library is a bitmap item, the following code displays "true" if the file that was imported
into the Library still exists.
var libItem = fl.getDocumentDOM().library.items[0];
fl.trace("sourceFileExists = "+ libItem.sourceFileExists);
See also
bitmapItem.sourceFileIsCurrent,
bitmapItem.sourceFilePath
bitmapItem.sourceFileIsCurrent
Availability
Flash CS4 Professional.
Usage
bitmapItem.sourceFileIsCurrent
40
Description
Read-only property; a Boolean value of true if the file modification date of the Library item is the same as the
modification date on disk of the file that was imported ;
false otherwise.
Example
Assuming the first item in the Library is a bitmap item, the following code displays "true" if the file that was imported
has not been modified on disk since it was imported:
var libItem = fl.getDocumentDOM().library.items[0];
fl.trace("fileIsCurrent = "+ libItem.sourceFileIsCurrent);
Read-only property; a string, expressed as a file:/// URI, that represents the path and name of the file that was imported
into the Library.
Example
The following example displays the name and source file path of any items in the library that are of type "bitmap":
for (idx in fl.getDocumentDOM().library.items) {
if (fl.getDocumentDOM().library.items[idx].itemType == "bitmap") {
var myItem = fl.getDocumentDOM().library.items[idx];
fl.trace(myItem.name + " source is " + myItem.sourceFilePath);
}
}
See also
bitmapItem.sourceFileExists
bitmapItem.useDeblocking
41
Availability
Flash CS4 Professional.
Usage
bitmapItem.useDeblocking
Description
Property; a Boolean value that specifies whether deblocking is enabled (true) or not (false).
Example
Assuming the first item in the Library is a bitmap item, the following code enables deblocking for the item:
var libItem = fl.getDocumentDOM().library.items[0];
libItem.useDeblocking = true;
bitmapItem.useImportedJPEGQuality
Availability
Flash MX 2004.
Usage
bitmapItem.useImportedJPEGQuality
EXTENDING FLASH CS4 PROFESSIONAL
BitmapItem object
Description
Property; a Boolean value that specifies whether to use the default imported JPEG quality (true) or not (false).
Available only for JPEG compression.
Example
The following code sets the useImportedJPEGQuality property of the first item in the library of the current
document to
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 (see Instance object).
Property summary
In addition to the properties of the Instance object, the CompiledClipInstance object has the following properties:
PropertyDescription
compiledClipInstance.accNameA string that is equivalent to the Name field in the Accessibility panel.
43
compiledClipInstance.actionScriptA string that represents the ActionScript for this instance; equivalent to
compiledClipInstance.descriptionA string that is equivalent to the Description field in the Accessibility panel.
compiledClipInstance.forceSimpleA Boolean value that enables and disables the children of the object to be
compiledClipInstance.shortcutA string that is equivalent to the Shortcut field in the Accessibility panel.
compiledClipInstance.silentA Boolean value that enables or disables the accessibility of the object;
compiledClipInstance.tabIndexAn integer that is equivalent to the Tab Index field in the Accessibility panel.
symbolInstance.actionScript.
accessible.
equivalent to the inverse logic of the Make Object Accessible setting in the
Accessibility panel.
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.
Example
The following example gets and sets the accessibility name of the first selected object:
EXTENDING FLASH CS4 PROFESSIONAL
CompiledClipInstance object
// 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:
44
// 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";
EXTENDING FLASH CS4 PROFESSIONAL
CompiledClipInstance object
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
same as the Make Child Objects Accessible option being unchecked. If
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;
forceSimple is false, it is the same as the
forceSimple is true, it is the
45
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
reader. 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.
EXTENDING FLASH CS4 PROFESSIONAL
CompiledClipInstance object
Usage
compiledClipInstance.silent
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
unchecked. If
silent is false, then Make Object Accessible is checked.
silent is true, then Make Object Accessible is
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.
46
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().selection[0].tabIndex = 1;
Chapter 7: compilerErrors object
Availability
Flash CS3 Professional.
Description
The compilerErrors object, which represents the Compiler Errors panel, is a property of the flash object (fl) and can
be accessed by
Method summary
The following methods can be used with the compilerErrors object:
MethodDescription
compilerErrors.clear()Clears the contents of the Compiler Errors panel.
compilerErrors.save()Saves the contents of the Compiler Errors panel to a local text file.
fl.compilerErrors (see flash object (fl)).
47
compilerErrors.clear()
Availability
Flash CS3 Professional.
Usage
compilerErrors.clear()
Parameters
None.
Returns
Nothing.
Description
Method; clears the contents of the Compiler Errors panel.
Example
The following example clears the contents of the Compiler Errors panel:
A Boolean value of true if the Component panel list is refreshed, false otherwise.
51
Description
Method; refreshes the Components panel’s list of components.
Example
The following example refreshes the Components panel:
fl.componentsPanel.reload();
Chapter 10: Contour object
Availability
Flash MX 2004.
Description
A Contour object represents a closed path of half edges on the boundary of a shape.
Method summary
You can use the following method with the Contour object:
MethodDescription
contour.getHalfEdge()Returns a HalfEdge object on the contour of the selection.
Property summary
You can use the following properties with the Contour object:
52
PropertyDescription
contour.fillA Fill object.
contour.interiorRead-only; the value is true if the contour encloses an area; false otherwise.
contour.orientationRead-only; an integer indicating the orientation of the contour.
contour.fill
Availability
Flash CS4 Professional.
Usage
contour.fill
Description
Property; a Fill object.
Example
Assuming that you have a contour with a fill selected, the following example displays the contour’s fill color in the
Output panel:
var insideContour = fl.getDocumentDOM().selection[0].contours[1];
var insideFill = insideContour.fill;
fl.trace(insideFill.color);
EXTENDING FLASH CS4 PROFESSIONAL
Contour object
contour.getHalfEdge()
Availability
Flash MX 2004.
Usage
contour.getHalfEdge()
Parameters
None.
Returns
A HalfEdge object.
Description
Method; returns a HalfEdge object on the contour of the selection.
Example
This example traverses all the contours of the selected shape and shows the coordinates of the vertices in the Output
panel:
53
// with a shape selected
var elt = fl.getDocumentDOM().selection[0];
elt.beginEdit();
var contourArray = elt.contours;
var contourCount = 0;
for (i=0;i<contourArray.length;i++)
{
var contour = contourArray[i];
contourCount++;
var he = contour.getHalfEdge();
var iStart = he.id;
var id = 0;
while (id != iStart)
{
// Get the next vertex.
var vrt = he.getVertex();
var x = vrt.x;
var y = vrt.y;
fl.trace("vrt: " + x + ", " + y);
he = he.getNext();
id = he.id;
}
}
elt.endEdit();
EXTENDING FLASH CS4 PROFESSIONAL
Contour object
contour.interior
Availability
Flash MX 2004.
Usage
contour.interior
Description
Read-only property; the value is true if the contour encloses an area; false otherwise.
Example
This example traverses all the contours of the selected shape and shows the value of the interior property for 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++) {
var contour = contourArray[i];
fl.trace("Next Contour, interior:" + contour.interior );
contourCount++;
}
elt.endEdit();
54
contour.orientation
Availability
Flash MX 2004.
Usage
contour.orientation
Description
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++) {
var contour = contourArray[i];
fl.trace("Next Contour, orientation:" + contour.orientation);
contourCount++;
}
elt.endEdit();
EXTENDING FLASH CS4 PROFESSIONAL
Contour object
55
Chapter 11: Document object
Availability
Flash MX 2004.
Description
The Document object represents the Stage. That is, only FLA files are considered documents. To return the Document
object for the current document, use
Method summary
You can use the following methods with the Document object:
MethodDescription
document.addDataToDocument()Stores specified data with a document.
document.addDataToSelection()Stores specified data with the selected object(s).
document.addFilter()Applies a filter to the selected objects.
fl.getDocumentDOM().
56
document.addItem()Adds an item from any open document or library to the
document.addNewLine()Adds a new path between two points.
document.addNewOval()Adds a new Oval object in the specified bounding rectangle.
document.addNewPrimitiveOval()Adds a new oval primitive fitting into the specified bounds.
document.addNewPrimitiveRectangle()Adds a new rectangle primitive fitting into the specified
document.addNewPublishProfile()Adds a new publish profile and makes it the current one.
document.addNewRectangle()Adds a new rectangle or rounded rectangle, fitting it into the
document.addNewScene()Adds a new scene (Timeline object) as the next scene after the
document.addNewText()Inserts a new empty text field.
document.align()Aligns the selection.
document.allowScreens()Use this method before using the
document.arrange()Arranges the selection on the Stage.
document.breakApart()Performs a break-apart operation on the current selection.
document.canEditSymbol()Indicates whether the Edit Symbols menu and functionality are
specified Document object.
bounds.
specified bounds.
currently selected scene and makes the new scene the
currently selected scene.
document.screenOutline property.
enabled.
document.canRevert()Determines whether you can use the document.revert() or
document.canSaveAVersion()Determines whether a version of the specified document can
fl.revertDocument() method successfully.
be saved to the Version Cue server.
MethodDescription
EXTENDING FLASH CS4 PROFESSIONAL
Document object
57
document.canTestMovie()Determines whether you can use the
document.canTestScene()Determines whether you can use the
document.changeFilterOrder()Changes the index of the filter in the Filters list.
document.clipCopy()Copies the current selection from the document to the
document.testMovie() method successfully.
document.testScene() method successfully.
Clipboard.
document.clipCut()Cuts the current selection from the document and writes it to
the Clipboard.
document.clipPaste()Pastes the contents of the Clipboard into the document.
document.close()Closes the specified document.
document.convertLinesToFills()Converts lines to fills on the selected objects.
document.convertToSymbol()Converts the selected Stage item(s) to a new symbol.
document.crop()Uses the top selected drawing object to crop all selected
drawing objects underneath it.
document.deleteEnvelope()Deletes the envelope (bounding box that contains one or
more objects) from the selected object.
document.deletePublishProfile()Deletes the currently active profile, if there is more than one.
document.deleteScene()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.
document.deleteSelection()Deletes the current selection on the Stage.
document.disableAllFilters()Disables all filters on the selected objects.
document.disableFilter()Disables the specified filter in the Filters list.
document.disableOtherFilters()Disables all filters except the one at the specified position in
the Filters list.
document.distribute()Distributes the selection.
document.distributeToLayers()Performs a distribute-to-layers operation on the current
selection; equivalent to selecting Distribute to Layers.
document.documentHasData()Checks the document for persistent data with the specified
name.
document.duplicatePublishProfile()Duplicates the currently active profile and gives the duplicate
version focus.
document.duplicateScene()Makes a copy of the currently selected scene, giving the new
scene a unique name and making it the current scene.
document.duplicateSelection()Duplicates the selection on the Stage.
document.editScene()Makes the specified scene the currently selected scene for
editing.
document.enableAllFilters()Enables all the filters on the Filters list for the selected object(s).
document.enableFilter()Enables the specified filter for the selected object(s).
MethodDescription
EXTENDING FLASH CS4 PROFESSIONAL
Document object
58
document.enterEditMode()Switches the authoring tool into the editing mode specified by
the parameter.
document.exitEditMode()Exits from symbol-editing mode and returns focus to the next
level up from the editing mode.
document.exportPNG()Exports the document as one or more PNG files.
document.exportPublishProfile()Exports the currently active profile to an XML file.
document.exportPublishProfileString() Returns a string that specifies, in XML format, the specified
profile.
document.exportSWF()Exports the document in the Flash SWF format.
document.getAlignToDocument()Identical to retrieving the value of the To Stage button in the
Align panel.
document.getBlendMode()Returns a string that specifies the blending mode for the
selected object(s).
document.getCustomFill()Retrieves the fill object of the selected shape, or the Tools
panel and Property inspector if specified.
document.getCustomStroke()Returns the stroke object of the selected shape, or the Tools
panel and Property inspector if specified.
document.getDataFromDocument()Retrieves the value of the specified data.
document.getElementProperty()Gets the specified Element property for the current selection.
document.getElementTextAttr()Gets a specified TextAttrs property of the selected Text
objects.
document.getFilters()Returns an array that contains the list of filters applied to the
currently selected object(s).
document.getMetadata()Returns a string containing the XML metadata associated with
the document.
document.getMobileSettings()Returns the string passed to
document.getPlayerVersion()Returns a string that represents the targeted player version for
document.setMobileSettings().
the specified document.
document.getSelectionRect()Gets the bounding rectangle of the current selection.
document.getTextString()Gets the currently selected text.
document.getTimeline()Retrieves the current Timeline object in the document.
document.getTransformationPoint()Gets the location of the transformation point of the current
selection.
document.group()Converts the current selection to a group.
document.importFile()Imports a file into the document.
document.importPublishProfile()Imports a profile from a file.
document.importPublishProfileString() Imports an XML string that represents a publish profile and sets
it as the current profile.
document.importSWF()Imports a SWF file into the document.
MethodDescription
EXTENDING FLASH CS4 PROFESSIONAL
Document object
59
document.intersect()Creates an intersection drawing object from all selected
drawing objects.
document.match()Makes the size of the selected objects the same.
document.mouseClick()Performs a mouse click from the Selection tool.
document.mouseDblClk()Performs a double mouse click from the Selection tool.
document.moveSelectedBezierPointsBy() If the selection contains at least one path with at least one
Bézier point selected, this method moves all selected Bézier
points on all selected paths by the specified amount.
document.moveSelectionBy()Moves selected objects by a specified distance.
document.optimizeCurves()Optimizes smoothing for the current selection, allowing
multiple passes, if specified, for optimal smoothing; equivalent
to selecting Modify > Shape > Optimize.
document.publish()Publishes the document according to the active publish
document.punch()Uses the top selected drawing object to punch through all
selected drawing objects underneath it.
document.removeAllFilters()Removes all filters from the selected object(s).
document.removeDataFromDocument()Removes persistent data with the specified name that has
been attached to the document.
document.removeDataFromSelection()Removes persistent data with the specified name that has
been attached to the selection.
document.removeFilter()Removes the specified filter from the Filters list of the selected
object(s).
document.renamePublishProfile()Renames the current profile.
document.renameScene()Renames the currently selected scene in the Scenes panel.
document.reorderScene()Moves the specified scene before another specified scene.
document.resetOvalObject()Sets all values in the Property inspector to default Oval object
settings.
document.resetRectangleObject()Sets all values in the Property inspector to default Rectangle
object settings.
document.resetTransformation()Resets the transformation matrix; equivalent to selecting
Modify > Transform > Remove Transform.
document.revert()Reverts the specified document to its previously saved version;
equivalent to selecting File > Revert.
document.revertToLastVersion()Reverts the specified document to the version stored on the
Version Cue server and logs any errors to the Output panel.
document.rotate3DSelection()Applies a 3D rotation to the selection.
document.rotateSelection()Rotates the selection by a specified number of degrees.
document.save()Saves the document in its default location; equivalent to
selecting File > Save.
MethodDescription
EXTENDING FLASH CS4 PROFESSIONAL
Document object
60
document.saveAndCompact()Saves and compacts the file; equivalent to selecting File > Save
and Compact.
document.saveAVersion()Saves a version of the specified document to the Version Cue
server.
document.scaleSelection()Scales the selection by a specified amount; equivalent to using
the Free Transform tool to scale the object.
document.selectAll()Selects all items on the Stage; equivalent to pressing
Control+A (Windows) or Command+A (Macintosh) or
selecting Edit > Select All.
document.selectNone()Deselects any selected items.
document.setAlignToDocument()Sets the preferences for document.align(),
document.distribute(), document.match(), and
document.space() to act on the document; equivalent to
enabling the To Stage button in the Align panel.
document.setBlendMode()Sets the blending mode for the selected objects.
document.setCustomFill()Sets the fill settings for the Tools panel, Property inspector, and
any selected shapes.
document.setCustomStroke()Sets the stroke settings for the Tools panel, Property inspector,
and any selected shapes.
document.setElementProperty()Sets the specified Element property on selected object(s) in
the document.
document.setElementTextAttr()Sets the specified TextAttrs property of the selected text
items to the specified value.
document.setFillColor()Changes the fill color of the selection to the specified color.
document.setFilterProperty()Sets a specified filter property for the currently selected
object(s).
document.setFilters()Applies filters to the selected objects.
document.setInstanceAlpha()Sets the opacity of the instance.
document.setInstanceBrightness()Sets the brightness for the instance.
document.setInstanceTint()Sets the tint for the instance.
document.setMetadata()Sets the XML metadata for the specified document,
overwriting any existing metadata.
document.setMobileSettings()Sets the value of an XML settings string in a mobile FLA file.
document.setOvalObjectProperty()Specifies a value for a specified property of primitive Oval
objects.
document.setPlayerVersion()Sets the version of the Flash Player targeted by the specified
document.
document.setRectangleObjectProperty() Specifies a value for a specified property of primitive Rectangle
objects.
document.setSelectionBounds()Moves and resizes the selection in a single operation.
document.setSelectionRect()Draws a rectangular selection marquee relative to the Stage,
using the specified coordinates.
EXTENDING FLASH CS4 PROFESSIONAL
MethodDescription
document.setStageVanishingPoint()Specifies the vanishing point for viewing 3D objects.
document.setStageViewAngle()Specifies the perspective angle for viewing 3D objects.
document.setStroke()Sets the color, width, and style of the selected strokes.
document.setStrokeColor()Changes the stroke color of the selection to the specified color.
document.setStrokeSize()Changes the stroke size of the selection to the specified size.
document.setStrokeStyle()Changes the stroke style of the selection to the specified style.
61
Document object
document.setTextRectangle()Changes the bounding rectangle for the selected text item to
the specified size.
document.setTextSelection()Sets the text selection of the currently selected text field to the
values specified by the
document.setTextString()Inserts a string of text.
document.setTransformationPoint()Moves the transformation point of the current selection.
document.skewSelection()Skews the selection by a specified amount.
document.smoothSelection()Smooths the curve of each selected fill outline or curved line.
document.space()Spaces the objects in the selection evenly.
document.straightenSelection()Straightens the currently selected strokes; equivalent to using
startIndex and endIndex values.
the Straighten button in the Tools panel.
document.swapElement()Swaps the current selection with the specified one.
document.swapStrokeAndFill()Swaps the Stroke and Fill colors.
document.synchronizeWithHeadVersion() Synchronizes the specified document with the most current
version on the Version Cue server and logs any errors to the
Output panel.
document.testMovie()Executes a Test Movie operation on the document.
document.testScene()Executes a Test Scene operation on the current scene of the
document.
document.traceBitmap()Performs a trace bitmap on the current selection; equivalent to
selecting Modify > Bitmap > Trace Bitmap.
document.transformSelection()Performs a general transformation on the current selection by
applying the matrix specified in the arguments.
document.translate3DCenter()Sets the XYZ position around which the selection is translated
or rotated.
document.translate3DSelection()Applies a 3D translation to the selection.
document.unGroup()Ungroups the current selection.
document.union()Combines all selected shapes into a drawing object.
document.unlockAllElements()Unlocks all locked elements on the currently selected frame.
document.xmlPanel()Posts a XMLUI dialog box.
Property summary
You can use the following properties with the Document object.
EXTENDING FLASH CS4 PROFESSIONAL
PropertyDescription
document.accNameA string that is equivalent to the Name field in the Accessibility panel.
62
Document object
document.as3AutoDeclareA Boolean value that describes whether the instances placed on the Stage
are automatically added to user-defined timeline classes.
document.as3DialectA string that describes the ActionScript 3.0 “dialect” being used in the
specified document.
document.as3ExportFrameAn integer that specifies in which frame to export ActionScript 3.0 classes.
document.as3StrictModeA Boolean value that specifies whether the ActionScript 3.0 compiler
should compile with the Strict Mode option turned on or off.
document.as3WarningsModeA Boolean value that specifies whether the ActionScript 3.0 compiler
should compile with the Warnings Mode option turned on or off.
document.asVersionAn integer that specifies which version of ActionScript is being used in the
specified file.
document.autoLabelA Boolean value that is equivalent to the Auto Label check box in the
Accessibility panel.
document.backgroundColorA string, hexadecimal value, or integer that represents the background
color.
document.currentPublishProfileA string that specifies the name of the active publish profile for the
specified document.
document.currentTimelineAn integer that specifies the index of the active timeline.
document.descriptionA string that is equivalent to the Description field in the Accessibility
panel.
document.docClassSpecifies the top-level ActionScript 3.0 class associated with the
document.
document.externalLibraryPathA string that contains a list of items in the document’s ActionScript 3.0
External library path, which specifies the location of SWC files used as
runtime shared libraries.
document.forceSimpleA Boolean value that specifies whether the children of the specified object
are accessible.
document.frameRateA float value that specifies the number of frames displayed per second
when the SWF file plays; the default is 12.
document.heightAn integer that specifies the height of the document (Stage) in pixels.
document.idA unique integer (assigned automatically) that identifies a document
during a Flash session.
document.libraryRead-only; the library object for a document.
document.libraryPathA string that contains a list of items in the document’s ActionScript 3.0
Library path, which specifies the location of SWC files or folders containing
SWC files.
document.livePreviewA Boolean value that specifies whether Live Preview is enabled.
document.nameRead-only; a string that represents the name of a document (FLA file).
document.pathRead-only; a string that represents the path of the document, in a
platform-specific format.
document.pathURIRead-only; a string that represents the path of the document, expressed as
a file:/// URI.
EXTENDING FLASH CS4 PROFESSIONAL
PropertyDescription
document.publishProfilesRead-only; an array of the publish profile names for the document.
document.screenOutlineRead-only; the current ScreenOutline object for the document.
document.selectionAn array of the selected objects in the document.
document.silentA Boolean value that specifies whether the object is accessible.
63
Document object
document.sourcePathA string that contains a list of items in the document’s ActionScript 3.0
document.timelinesRead-only; an array of Timeline objects (see Timeline object).
document.viewMatrixRead-only; a Matrix object.
document.widthAn integer that specifies the width of the document (Stage) in pixels.
document.zoomFactorSpecifies the zoom percent of the Stage at authoring time.
Source path, which specifies the location of ActionScript class files.
document.accName
Availability
Flash MX 2004.
Usage
document.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.
Example
The following example sets the accessibility name of the document to "Main Movie":
fl.getDocumentDOM().accName = "Main Movie";
The following example gets the accessibility name of the document:
fl.trace(fl.getDocumentDOM().accName);
document.addDataToDocument()
Availability
Flash MX 2004.
Usage
document.addDataToDocument(name, type, data)
Parameters
name A string that specifies the name of the data to add.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
type A string that defines the type of data to add. Acceptable values 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 a document. Data is written to the FLA file and is available to JavaScript when the
file reopens.
Example
The following example adds an integer value of 12 to the current document:
name A string that specifies the name of the persistent data.
type Defines the type of data. Acceptable values 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.
Example
The following example adds an integer value of 12 to the selected object:
position 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.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
item An Item object that specifies the item to add and the library from which to add it (see Item object).
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);
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:
66
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, endpoint)
Parameters
startpoint A pair of floating-point numbers that specify the x and y coordinates where the line 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.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
Example
The following example adds a line between the specified starting point and ending point:
boundingRectangle A rectangle that specifies the bounds of the oval to be added. For information on the format of
boundingRectangle, see
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.
document.addNewRectangle().
67
bSuppressStroke A Boolean value that, if set to true, causes the method to create the shape without a stroke. The
default value is
false. This parameter is optional.
Returns
Nothing.
Description
Method; adds a new Oval object 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 both bSuppressFill and bSuppressStroke are set to
true, the method has no effect.
Example
The following example adds a new oval within the specified coordinates; it is 164 pixels in width and 178 pixels in
height:
boundingRectangle A rectangle that specifies the bounds within which the new oval primitive is added. For
information on the format of boundingRectangle, see
bSuppressFill A Boolean value that, if set to true, causes the method to create the oval without a fill. The default
value is
bSuppressStroke A Boolean value that, if set to true, causes the method to create the oval without a stroke. The
default value is
false. This parameter is optional.
false. This parameter is optional.
Returns
Nothing.
document.addNewRectangle().
68
Description
Method; adds a new oval primitive fitting into the specified bounds. This method performs the same operation as the
Oval Primitive tool. The oval primitive uses the document's current default stroke and fill attributes and is added on
the current frame and layer. If both bSuppressFill and bSuppressStroke are set to
true, the method has no effect.
Example
The following example adds oval primitives within the specified coordinates, with and without fill and stroke:
// Add an oval primitive with fill and stroke
fl.getDocumentDOM().addNewPrimitiveOval({left:0,top:0,right:100,bottom:100});
// Add an oval primitive without a fill
fl.getDocumentDOM().addNewPrimitiveOval({left:100,top:100,right:200,bottom:200}, true);
// Add an oval primitive without a stroke
fl.getDocumentDOM().addNewPrimitiveOval({left:200,top:200,right:300,bottom:300},false,true);
rect A rectangle that specifies the bounds within which the new rectangle primitive is added. For information on the
format of boundingRectangle, see
roundness An integer between 0 and 999 that represents the number of points used to specify how much the corners
document.addNewRectangle().
should be rounded.
bSuppressFill A Boolean value that, if set to true, causes the method to create the rectangle without a fill. The
default value is
bSuppressStrokeA Boolean value that, if set to true, causes the method to create the rectangle without a stroke.
false. This parameter is optional.
The default value is false. This parameter is optional.
Returns
Nothing.
Description
Method; adds a new rectangle primitive fitting into the specified bounds. This method performs the same operation
as the Rectangle Primitive tool. The rectangle primitive uses the document's current default stroke and fill attributes
and is added on the current frame and layer. If both bSuppressFill and bSuppressStroke are set to
true, the method has
no effect.
69
Example
The following example adds rectangle primitives within the specified coordinates, with and without fill and stroke, and
with different amounts of roundness:
// Add a rectangle primitive with fill and stroke
fl.getDocumentDOM().addNewPrimitiveRectangle({left:0,top:0,right:100,bottom:100}, 0);
// Add a rectangle primitive without a fill
fl.getDocumentDOM().addNewPrimitiveRectangle({left:100,top:100,right:200,bottom:200}, 20,
true);
// Add a rectangle primitive without a stroke
fl.getDocumentDOM().addNewPrimitiveRectangle({left:200,top:200,right:300,bottom:300},
50,false,true);
See also
document.addNewRectangle()
document.addNewPublishProfile()
Availability
Flash MX 2004.
Usage
document.addNewPublishProfile([profileName])
Parameters
profileName The unique name of the new profile. If you do not specify a name, a default name is provided. This
parameter is optional.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
Returns
An integer that is the index of the new profile in the profiles list. Returns -1 if a new profile cannot be created.
Description
Method; adds a new publish profile and makes it the current one.
Example
The following example adds a new publish profile with a default name and then displays the name of the profile in the
Output panel:
boundingRectangle A rectangle that specifies the bounds within which the new rectangle is added, in the format
{left:value1,top:value2,right:value3,bottom:value4}. The left and top values specify the location of the
upper left corner (e.g.,
specify the location of the lower-right corner. Therefore, the width of the rectangle is the difference in value between
left and right, and the height of the rectangle is the difference in value between top and bottom.
In other words, the rectangle bounds do not all correspond to the values shown in the Property inspector. The left
top values correspond to the X and Y values in the Property inspector, respectively. However, the right and
and
bottom values don’t correspond to the W and H values in the Property inspector. For example, consider a rectangle
with the following bounds:
{left:10,top:10,right:50,bottom:100}
This rectangle would display the following values in the Property inspector:
X = 10, Y = 10, W = 40, H = 90
left:0,top:0 represents the upper left corner of the Stage) and the right and bottom values
roundness An integer value from 0 to 999 that specifies the roundness to use for the 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.
EXTENDING FLASH CS4 PROFESSIONAL
bSuppressStroke A Boolean value that, if set to true, causes the method to create the rectangle without a stroke.
The default value is
false. This parameter is optional.
Document object
Returns
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 both bSuppressFill and bSuppressStroke are set to
true, the method
has no effect.
Example
The following example adds a new rectangle with no rounding on the corners within the specified coordinates; it is 100
pixels in width and in height:
name 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.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
Example
The following example adds a new scene named myScene after the current scene in the current document. The variable
success will be true when the new scene is created; false otherwise.
var success = fl.getDocumentDOM().addNewScene("myScene");
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();
"Scene 2".
document.addNewText()
Availability
Flash MX 2004; optional text parameter added in Flash CS3 Professional.
Usage
document.addNewText(boundingRectangle [, text ])
72
Parameters
boundingRectangle Specifies the size and location of the text field. For information on the format of
boundingRectangle, see
text An optional string that specifies the text to place in the field. If you omit this parameter, the selection in the Tools
document.addNewRectangle().
panel switches to the Text tool. Therefore, if you don’t want the selected tool to change, pass a value for text.
Returns
Nothing.
Description
Method; inserts a new text field and optionally places text into the field. If you omit the text parameter, you can call
document.setTextString() to populate the text field.
Example
The following example creates a new text field in the upper left corner of the Stage and sets the text string to "Hello
alignmode A string that specifies how to align the selection. Acceptable values are "left", "right", "top",
"bottom", "vertical center", and "horizontal center".
bUseDocumentBoundsA Boolean value that, if set to true, causes the method to align to the bounds of the document.
Otherwise, the method uses the bounds of the selected objects. The default is
false. This parameter is optional.
Returns
Nothing.
Description
Method; aligns the selection.
Example
The following example aligns objects to the 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:
A Boolean value: true if document.screenOutline can be used safely; false otherwise.
Description
Method; use before using the document.screenOutline property. If this method returns the value true, you can
safely access
document without screens.
document.screenOutline; Flash displays an error if you access document.screenOutline in a
Example
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.");
}
See also
document.screenOutline
document.arrange()
Availability
Flash MX 2004.
Usage
document.arrange(arrangeMode)
EXTENDING FLASH CS4 PROFESSIONAL
Document object
74
Parameters
arrangeMode Specifies the direction in which to move the selection. Acceptable values are "back", "backward",
"forward", and "front". It provides the same capabilities as these options provide on the Modify > Arrange menu.
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.as3AutoDeclare
Availability
Flash CS3 Professional.
Usage
document.as3AutoDeclare
Description
Property; a Boolean value that describes whether the instances placed on the Stage are automatically added to userdefined timeline classes. The default value is
true.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
Example
The following example specifies that instances placed on the Stage in the current document must be manually added
to user-defined timeline classes.
fl.getDocumentDOM().as3AutoDeclare=false;
document.as3Dialect
Availability
Flash CS3 Professional.
Usage
document.as3Dialect
Description
Property; a string that describes the ActionScript 3.0 “dialect” being used in the specified document. The default value
"AS3"
is
. If you wish to allow prototype classes, as permitted in earlier ECMAScript specifications, set this value to
"ES"
75
.
Example
The following example specifies that the dialect being used in the current document is ECMAScript:
fl.getDocumentDOM().as3Dialect="ES";
See also
document.asVersion
document.as3ExportFrame
Availability
Flash CS3 Professional.
Usage
document.as3ExportFrame
Description
Property; an integer that specifies in which frame to export ActionScript 3.0 classes. By default, classes are exported in
Frame 1.
Example
The following example changes the frame in which classes are exported from 1 (the default) to 5.
var myDocument = fl.getDocumentDOM();
fl.outputPanel.trace("'Export classes in frame:' value before modification is " +
myDocument.as3ExportFrame);
myDocument.as3ExportFrame = 5;
fl.outputPanel.trace("'Export classes in frame:' value after modification is " +
myDocument.as3ExportFrame);
EXTENDING FLASH CS4 PROFESSIONAL
Document object
document.as3StrictMode
Availability
Flash CS3 Professional.
Usage
document.as3StrictMode
Description
Property; a Boolean value that specifies whether the ActionScript 3.0 compiler should compile with the Strict Mode
option turned on (
compilation will not succeed if those errors exist. The default value is
Example
The following example turns off the Strict Mode compiler option.
var myDocument = fl.getDocumentDOM();
fl.outputPanel.trace("Strict Mode value before modification is " + myDocument.as3StrictMode);
myDocument.as3StrictMode = false;
fl.outputPanel.trace("Strict Mode value after modification is " + myDocument.as3StrictMode);
true) or off (false). Strict Mode causes warnings to be reported as errors, which means that
true.
76
See also
document.as3WarningsMode
document.as3WarningsMode
Availability
Flash CS3 Professional.
Usage
document.as3WarningsMode
Description
Property; a Boolean value that specifies whether the ActionScript 3.0 compiler should compile with the Warnings
Mode option turned on (
discovering incompatibilities when updating ActionScript 2.0 code to ActionScript 3.0. The default value is
Example
The following example turns off the Warnings Mode compiler option.
var myDocument = fl.getDocumentDOM();
fl.outputPanel.trace("Warnings Mode value before modification is " +
myDocument.as3WarningsMode);
myDocument.as3WarningsMode = false;
fl.outputPanel.trace("Warnings Mode value after modification is " +
myDocument.as3WarningsMode);
true) or off (false). Warnings Mode causes extra warnings to be reported that are useful for
true.
EXTENDING FLASH CS4 PROFESSIONAL
Document object
See also
document.as3StrictMode
document.asVersion
Availability
Flash CS3 Professional.
Usage
document.asVersion
Description
Property; an integer that specifies which version of ActionScript is being used in the specified document. Acceptable
values are 1, 2, and 3.
To determine the targeted player version for the specified document, use document.getPlayerVersion(); this
method returns a string, so it can be used by Flash® Lite™ players.
77
Example
The following example sets the version of ActionScript in the current document to ActionScript 2.0 if it is currently
set as ActionScript 1.0.
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);
EXTENDING FLASH CS4 PROFESSIONAL
Document object
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; the color of the background, in one of the following formats:
• A string in the format "#RRGGBB" or "#RRGGBBAA"
• A hexadecimal number in the format 0xRRGGBB
• An integer that represents the decimal equivalent of a hexadecimal number
78
Example
The following example sets the background color to black:
fl.getDocumentDOM().backgroundColor = '#000000';
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();
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.