Getting started with ActionScript

The ActionScript® scripting language lets you add complex interactivity, playback control, and data display to your application. You can add ActionScript in the authoring environment by using the Actions panel, Script window, or an external editor.

ActionScript follows its own rules of syntax, reserved keywords, and lets you use variables to store and retrieve information. ActionScript includes a large library of built‑in classes that let you create objects to perform many useful tasks. For more information on ActionScript, see the following Help titles:

You don’t need to understand every ActionScript element to begin scripting; if you have a clear goal, you can start building scripts with simple actions.

ActionScript and JavaScript are both rooted in the ECMA-262 standard, the international standard for the ECMAScript scripting language. For this reason, developers who are familiar with JavaScript should find ActionScript immediately familiar. For more information about ECMAScript, go to ecma-international.org.

Adobe recommends...

Adobe recommends...

Which version of ActionScript should you use?

Animate includes more than one version of ActionScript to meet the needs of different kinds of developers and playback hardware. ActionScript 3.0 and 2.0 are not compatible with each other.

 

  • ActionScript 3.0 executes extremely fast. This version requires somewhat more familiarity with object-oriented programming concepts than the other ActionScript versions. ActionScript 3.0 is fully compliant with the ECMAScript specification, offers better XML processing, an improved event model, and an improved architecture for working with onscreen elements. FLA files that use ActionScript 3.0 cannot include earlier versions of ActionScript.

  • (Deprecated with Animate CC only) ActionScript 2.0 is simpler to learn than ActionScript 3.0. Although Flash Player runs compiled ActionScript 2.0 code slower than compiled ActionScript 3.0 code, ActionScript 2.0 is still useful for many kinds of projects that are not computationally intensive; for example, more design-oriented content. ActionScript 2.0 is also based on the ECMAScript spec, but is not fully compliant.

  • (Deprecated with Animate CC) ActionScript 1.0 is the simplest form of ActionScript, and is still used by some versions of the Flash Lite Player. ActionScript 1.0 and 2.0 can coexist in the same FLA file.

  • (Deprecated with Animate CC) Flash Lite 2.x ActionScript is a subset of ActionScript 2.0 that is supported by Flash Lite 2.x running on mobile phones and devices.

  • (Deprecated with Animate CC) Flash Lite 1.x ActionScript is a subset of ActionScript 1.0 that is supported by Flash Lite 1.x running on mobile phones and devices.

 

Using the ActionScript documentation

Because there are multiple versions of ActionScript (2.0 and 3.0), and multiple ways of incorporating it into your FLA files, there are several different ways to learn ActionScript.

This chapter describes the graphical user interface for working with ActionScript. This interface includes the Actions panel, Script window, Script Assist mode, Behaviors panel, Output panel, and Compiler Errors panel. These topics apply to all versions of ActionScript.

Other ActionScript documentation from Adobe will help you learn about the individual versions of ActionScript.

Ways of working with ActionScript

There are several ways to work with ActionScript.

  • (Deprecated with Animate CC) Script Assist mode lets you add ActionScript to your FLA file without writing the code yourself. You select actions, and the software presents you with a user-interface for entering the parameters required for each one. You must know a little about what functions to use to accomplish specific tasks, but you don’t have to learn syntax. Many designers and non-programmers use this mode.

  • (Deprecated with Animate CC) Behaviors also let you add code to your file without writing it yourself. Behaviors are prewritten scripts for common tasks. You can add a behavior and then easily configure it in the Behaviors panel. Behaviors are available only for ActionScript 2.0 and earlier.

  • Writing your own ActionScript gives you the greatest flexibility and control over your document, but it requires you to become familiar with the ActionScript language and conventions.

  • Components are prebuilt movie clips that help you implement complex functionality. A component can be a simple user interface control, such as a check box, or it can be a complicated control, such as a scroll pane. You can customize a component’s functionality and appearance, and you can download components created by other developers. Most components require you to write some ActionScript code of your own to trigger or control a component. For more information, see Using ActionScript 3.0 Components.

 

Writing ActionScript

When you write ActionScript code in the authoring environment, you use the Actions panel or Script window. The Actions panel and Script window contain a full-featured code editor that includes code hinting and coloring, code formatting, syntax highlighting, debugging, line numbers, word wrapping, and support for Unicode.

  • Use the Actions panel to write scripts that are part of your Animate document (that is, scripts that are embedded in the FLA file). The Actions panel provides features such as the Actions toolbox, which gives you quick access to the core ActionScript language elements, in which you are prompted for the elements needed to create scripts.

  • Use the Script window if you want to write external scripts—that is, scripts or classes that are stored in external files. (You can also use a text editor to create an external AS file.) The Script window includes code-assistance features such as code hinting and coloring, syntax checking, and auto-formatting.

Additional recommended community content

The following articles and tutorials provide additional detailed information about working with ActionScript:

The Actions panel

Looking for the Language Reference?

To find reference documentation for a specific ActionScript language element, do one of the following:

Note:

To open the Help in a web browser instead of the Community Help application, see this article: http://kb2.adobe.com/community/publishing/916/cpsid_91609.html.

Learning ActionScript

To learn about writing ActionScript, use these resources:

Note:

ActionScript 3.0 and 2.0 are not compatible with each other. You must choose only one version to use in each FLA file you create.

Overview of the Actions panel

To create scripts embedded in a FLA file, enter ActionScript directly into the Actions panel (Window > Actions or press F9).

Actions Panel

The Actions panel consists of two panes:

Script pane

Lets you type ActionScript code, which is associated with the currently selected frame.

Script navigator

Lists the scripts in your Animate document, and lets you move quickly between them. Click an item in the Script navigator to view the script in the Script pane.

The Actions panel let you access the code-assistance features that help simplify and streamline coding in ActionScript.

  • Run Script: Runs the script
  • Pin Script: Pins the script to the pin tabs of individual scripts in the Script pane and move them accordingly. This feature is useful if you have not organized the code within your FLA file into one central location or if you are using multiple scripts.You can pin a script to retain the open location of the code in the Actions panel and toggle between the various open scripts. This can be especially useful when debugging.
  • Insert Instance Path and Name: Helps you set an absolute or relative target path for an action in the script.
  • Find: Finds and replaces text in your script.
  • Format Code: Helps to format the code.
  • Code Snippets:Opens the Code Snippets panel that displays sample code snippets.
  • Help: Displays reference information for the ActionScript element that is selected in the Script pane. For example, if you click an import statement and then click Help, the reference information for import appears in the Help panel.

Overview of the Output panel

When you test any doc type, the Output panel displays information or warning related to operations such as document conversions, publish etc. To display this information, add trace() statements to your code or use the List Objects and List Variables commands.

If you use the trace() statement in your scripts, you can send specific information to the Output panel when the SWF file runs. This could include notes about the status of the SWF file status or the value of an expression. 

Output panel

The Output panel consists of the following menu options:

  • Copy: Copies all the contents of the Output panel to the computer's Clipboard. To copy a selected portion of the output, select the area you want to copy and then select Copy.
  • Clear: Clears the content of the output panel.
  • Show Output: Displays the content of the output panel.
  • Lock: Locks the panel. You can only resize the panel but you cannot move or drag the panel. 
  • Help: Invokes the online help for the output panel.
  • Close: Closes the output panel.
  • Close Group: Closes the whole panel group. You can simultaneously dock multiple panels such as timeline, output panel, and compiler errors panel. 

 

Display or hide the Output panel

  •  Select Window > Output or press F2.

(Deprecated with Animate CC) Print ActionScript

  1. From the Actions panel pop‑up menu, select Print.
  2. Select Options and click Print.

    Because the printed copy won’t include information about file it came from, you should include information such as the name of the FLA file in a comment in the script.

Overview of Script window

The Script window lets you create external script files that you import into your application. These scripts can be ActionScript or Animate JavaScript files.

Script window

If you have more than one external file open, filenames are displayed on tabs across the top of the Script window.

In the Script window, you can use the following features: PinScript, find and replace, syntax coloring, format code, code hinting, code commenting, code collapse, debug options (ActionScript files only), and word wrap. The Script window also lets you display line numbers and hidden characters.

Create an external file in the Script window

  1. Select File > New.
  2. Select the type of external file you want to create (ActionScript file or Animate JavaScript file).

Edit an existing file in the Script window

  • To open an existing script, select File > Open, and then open an existing AS file.

  • To edit a script that is already open, click the document tab that shows the script’s name.

Tools in the Actions panel and Script window

The Actions panel let you access the code-assistance features that help simplify and streamline coding in ActionScript.

Find 

Finds and replaces text in your script.

Insert Target Path 

(Actions panel only) Helps you set an absolute or relative target path for an action in the script.

Help 

Displays reference information for the ActionScript element that is selected in the Script pane. For example, if you click an import statement and then click Help, the reference information for import appears in the Help panel.

Code Snippets

Opens the Code Snippets panel that displays sample code snippets.

Access context-sensitive Help from the Actions panel

  1. To select an item for reference, do any of the following:
    • Select an ActionScript term in the Actions panel toolbox pane (on the left side of the Actions panel).

    • Select an ActionScript term in the Actions panel in the Script pane.

    • Place the insertion point before an ActionScript term in the Actions panel in the Script pane.

  2. To open the Help panel reference page for the selected item, do one of the following:
    • Press F1.

    • Right-click the item and select View Help.

    • Click Help  above the Script pane.

Set ActionScript preferences

Whether you edit code in the Actions panel or the Script window, you can set and modify a single set of preferences.

  1. Select Edit > Preferences (Windows) or Animate > Preferences (Macintosh), and then click Code Editor in the Category list.

  2. Set any of these preferences:

    Automatic Indentation

    When automatic indentation is turned on, the text you type after an opening parenthesis “(“ or opening curly brace “{“ is automatically indented according to the Tab Size setting.

    Tab Size

    Specifies the number of characters a new line is indented.

    Code Hints

    Enables code hinting in the Script pane.

    Delay

    Specifies the delay (in seconds) before code hints are displayed. Note that the option is deprecated with Animate CC.

    Font

    Specifies the font used for your script.

    Open/Import

    Specifies the character encoding used when you open or import ActionScript files.

    Save/Export

    Specifies the character encoding used when you save or export ActionScript files.

    Reload Modified Files

    Specifies what happens when a script file is modified, moved, or deleted. Select Always, Never, or Prompt.

    Always

    No warning is displayed, and the file is automatically reloaded.

    Never

    No warning is displayed, and the file remains in the current state.

    Prompt

    (Default) A warning is displayed, and you can choose whether to reload the file.

    When you build applications with external scripts, this preference helps you avoid overwriting a script that a team member has modified since you opened the application, or avoid publishing the application with older versions of scripts. The warnings let you automatically close a script and reopen the newer, modified version.

    Syntax Colors

    Specifies code coloring in your scripts.

    ActionScript 3.0 Settings

    These buttons open the ActionScript Settings dialog boxes, where you can set source path, library path, and external library path for ActionScript 3.0.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy