What is Software? | What is Education? | What is Technology? | What is Research? | What is Wi-Fi? | What is Communication? | What is Customer Service?

Free SEO Tutorials & Help

Tutorials:   Adobe Flash   Adobe Photoshop   CorelDRAW   SEO  

Site Map

Website Development | Cable & Broadband Magazine | Solutions for Higher Education | Auction Anything Online

Adobe Flash Help & Tutorials

 Back to Topics

 

Process of Writing and Editing ActionScript 2.0 in Flash

About ActionScript and events

Organizing ActionScript code

Using the Actions panel and Script window

About the Actions panel

About the Script window

About coding in the Actions panel and Script window

 About the Actions panel and Script window toolbars

About ActionScript editing options

About ActionScript preferences

About triggering code hints

Using code hints

About typing objects to trigger code hints

About using suffixes to trigger code hints

About using comments to trigger code hints

Formatting code

Using syntax highlighting

Using line numbers and word wrap

Using Escape shortcut keys

Showing hidden characters

Using the Find tool

Checking syntax and punctuation

Importing and exporting scripts

About Actions panel features

About Script Assist

Pinning scripts in the Actions panel

Inserting target paths

About behaviors

About ActionScript publish settings

Modifying ActionScript publish settings

Modifying the classpath

Configuration files that install with Flash 8

 

About ActionScript and events

TOP

In Macromedia Flash Basic 8 and Macromedia Flash Professional 8, ActionScript code is executed when an event occurs: for example, when a movie clip is loaded, when a keyframe on the timeline is entered, or when the user clicks a button. Events can be triggered either by the user or by the system. Users click mouse buttons and press keys; the system triggers events when specific conditions are met or processes completed (the SWF file loads, the timeline reaches a certain frame, a graphic finishes downloading, and so on).

When an event occurs, you write an event handler to respond to the event with an action. Understanding when and where events occur will help you to determine how and where you will respond to the event with an action, and which ActionScript tools to use in each case.

Events can be grouped into a number of categories: mouse and keyboard events, which occur when a user interacts with your Flash application through the mouse and keyboard; clip events, which occur within movie clips; and frame events, which occur within frames on the timeline.

Mouse and keyboard events

A user interacting with your SWF file or application triggers mouse and keyboard events. For example, when the user rolls over a button, the Button.onRollOver or on(rollOver) event occurs; when the user clicks a button, the Button.onRelease event occurs; if a key on the keyboard is pressed, the on(keyPress) event occurs. You can write code on a frame or attach scripts to an instance to handle these events and add all the interactivity you desire.

Clip events

Within a movie clip, you may react to a number of clip events that are triggered when the user enters or exits the scene or interacts with the scene by using the mouse or keyboard. You might, for example, load an external SWF file or JPG image into the movie clip when the user enters the scene, or allow the user's mouse movements to reposition elements in the scene.

Frame events

On a main or movie clip timeline, a system event occurs when the playhead enters a keyframe--this is known as a frame event. Frame events are useful for triggering actions based on the passage of time (moving through the timeline) or for interacting with elements that are currently visible on the Stage. When you add a script to a keyframe, it is executed when the keyframe is reached during playback. A script attached to a frame is called a frame script.

One of the most common uses of frame scripts is to stop the playback when a certain keyframe is reached. This is done with the stop() function. You select a keyframe and then add the stop() function as a script element in the Actions panel.

When you've stopped the SWF file at a certain keyframe, you need to take some action. You could, for example, use a frame script to dynamically update the value of a label, to manage the interaction of elements on the Stage, and so on.

 

Organizing ActionScript code

TOP

You may attach scripts to keyframes and to object instances (movie clips, buttons, and other symbols). However, if your ActionScript code is scattered over many keyframes and object instances, debugging your application will be much more difficult. It will also be difficult to share your code between different Flash applications. Therefore, it's important to follow best practices for coding when you create ActionScript in Flash.

Rather than attaching your scripts to elements like keyframes, movie clips, and buttons, you should respond to events by calling functions that reside in a central location. One method is to attach embedded ActionScript to the first or second frame of a timeline whenever possible so you don't have to search through the FLA file to find all your code. A common practice is to create a layer called actions and place your ActionScript code there.

When you attach all your scripts to individual elements, you're embedding all your code in the FLA file. If sharing your code between other Flash applications is important to you, use the Script window or your favorite text editor to create an external ActionScript (AS) file.

By creating an external file, you make your code more modular and well organized. As your project grows, this convenience becomes much more useful than you might imagine. An external file aids debugging and also source control management if you're working on a project with other developers.

To use the ActionScript code contained in an external AS file, you create a script within the FLA file and then use the #include statement to access the code you've stored externally, as shown in the following example:

#include "../core/Functions.as"

You can also use ActionScript 2.0 to create custom classes. You must store custom classes in external AS files and use import statements in a script to get the classes exported into the SWF file, instead of using #include statements.

NOTE : ActionScript code in external files is compiled into a SWF file when you publish, export, test, or debug a FLA file. Therefore, if you make any changes to an external file, you must save the file and recompile any FLA files that use it.

When you write ActionScript in Flash 8, you use the Actions panel, the Script window, or both. When you use the Actions panel or Script window is dictated by how you respond to events, how you organize your code, and, most importantly, coding best practices.

When you use behaviors, which are predefined ActionScript functions, other workflow and code organization issues must be considered.

About writing scripts to handle events

Writing code for events can be categorized into two major groups: events that occur on the timeline (in keyframes) and those that occur on object instances (move clips, buttons, and components). The interactivity of your SWF file or application can be scattered over the many elements in your project, and you may be tempted to add scripts directly to these elements. However, Macromedia recommends that you do not add scripts directly to these elements (keyframes and objects). Instead, you should respond to events by calling functions that reside in a central location, as described in Organizing ActionScript code.

 

Using the Actions panel and Script window

TOP

To create scripts within a FLA file, you enter ActionScript directly into the Actions panel. To create external scripts that you include or import into your application, you can use the Script window (File > New and then select ActionScript File) or your preferred text editor.

When you use the Actions panel or Script window, you are using features of the ActionScript editor to write, format, and edit your code. Both the Actions panel and Script window have the Script pane (which is where you type your code) and the Actions toolbox. The Actions panel offers a few more code-assistance features than the Script window. Flash offers these features in the Actions panel because they are especially useful in the context of editing ActionScript within a FLA file.

To display the Actions panel, do one of the following:

  • Select Window > Actions.

  • Press F9.

To display the Script window, do one of the following:

  • To begin writing a new script, select File > New and then select ActionScript File.

  • 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.

 

About the Actions panel

TOP

You use the Actions panel to create ActionScript in a Flash document (a FLA file). The Actions panel consists of three panes, each of which supports you in creating and managing scripts.

Actions toolbox Use the Actions toolbox to browse a categorical list of ActionScript language elements (functions, classes, types, and so on) and then insert them into the Script pane. You can insert a script element into the Script pane either by double-clicking or dragging it directly into the Script pane. You can also add language elements to your scripts by using the Add (+) button on the Actions panel toolbar.

Script navigator The Script navigator displays a hierarchical list of Flash elements (movie clips, frames, and buttons) that contain scripts. Use the Script navigator to move quickly between all the scripts in your Flash document.

If you click an item in the Script navigator, the script associated with that item appears in the Script pane and the playhead moves to that position on the timeline. If you double-click an item in the Script navigator, the script gets pinned (locked in place).

Script pane The Script pane is where you type your code. The Script pane provides you with tools to create scripts in a full-featured editor (called the ActionScript editor) that includes code syntax formatting and checking, code hinting, code coloring, debugging, and other features that simplify creating scripts.

 

About the Script window

TOP

You can write and edit ActionScript in the Script window when you create a new ActionScript, Flash Communication, or Flash JavaScript file. You use the Script window to write and edit external script files. Syntax coloring, code hinting, and other editor options are supported in the Script window.

You can create external ActionScript, ActionScript communication, and Flash JavaScript files in the Script window. Depending upon the type of external script file you create, the Actions toolbox provides you with a complete list of the language elements available for each.

When you use the Script window, you'll notice that some of the other code-assistance features like Script navigator, Script Assist mode, and behaviors are unavailable. This is because these features are only useful in the context of creating a Flash document, not for creating an external script file.

You will also notice that many of the options available in the Actions panel are unavailable in the Script window. The Script window supports the following editor options: the Actions toolbox, find and replace, syntax checking, automatic formatting, code hinting, and debug options (ActionScript files only). Additionally, the Script window supports displaying line numbers, hidden characters, and word wrap.

To display the Script window:

  1. Select File > New.

  2. Select the type of external file you want to create (ActionScript file, Flash Communication file, or Flash JavaScript file).

You can have multiple external files open at the same time; filenames are displayed on tabs across the top of the Script window.

 

About coding in the Actions panel and Script window

TOP

The Script pane, where you edit code, is the primary element of both the Actions panel and the Script window. The Actions panel and Script window offer basic script editing and code-assistance features like code hinting, coloring, automatic formatting, and so on.

Features that help you edit code are accessible from the toolbar in the Actions panel or Script window, through the menu system, and in the Script pane itself.

 

About the Actions panel and Script window toolbars

TOP

The Actions panel and Script window toolbars contain links to the code-assistance features that help simplify and streamline coding in ActionScript. The toolbars are different depending on whether you are using the ActionScript editor in the Actions panel or the Script pane. The following image displays features found in the Actions panel toolbar. The marked options are only available in the Actions panel.

The features you find in the toolbar are discussed in detail in Using the Actions panel and Script window. A quick summary of the buttons you find on the toolbars of both the Actions panel and the Script window follows.

NOTE : Some of the following options are found in the Actions panel only. These features are marked Actions panel only.

Add a new item to the script Display all of the language elements that are also in the ActionScript toolbox. Selecting an item from the categorized list of language elements adds it to the script.

Find Find and replace text in your ActionScript code.

Insert target path Actions panel only. Assists you in setting an absolute or relative target path for an action in the script.

Check Syntax Check for syntax errors in the current script. Syntax errors are listed in the Output panel. For more information, see Checking syntax and punctuation.

Auto Format Format your script for proper coding syntax and improved readability. You can set autoformatting preferences in the Preferences dialog box, which is available from the Edit menu or from the Actions panel pop-up menu.

Show Code Hint If you've turned off automatic code hinting, you can use Show Code Hint to manually display a code hint for the line of code you're working on.

Debug Options Set and remove breakpoints in your script so that when you debug your Flash document, you can stop and then proceed line by line through your script. Debug options are now available in the Script window as well as the Actions panel, but only for ActionScript files. This option is disabled for ActionScript Communication and Flash JavaScript files. For more information about debugging your Flash documents.

Script Assist Actions panel only. In Script Assist mode, you are prompted to enter the elements needed to create scripts.

Reference Display a reference Help topic for the ActionScript language element that is selected in the Script pane. For example, if you click an import statement and then click Reference, the Help topic for import appears in the Help panel.

Pop-up menu Actions panel only. Contains the many commands and preferences that apply to the Actions panel or Script window. For example, you can set line numbers and word wrapping in the ActionScript editor, access the ActionScript preferences, and import or export scripts.

 

About ActionScript editing options

TOP

The Script window and Actions panel provide you with many code-assistance features--tools that make writing and maintaining your scripts much easier. These tool options are available from the Actions panel or Script window toolbar and the Actions panel pop-up menu. When you edit ActionScript in the Script window, these options are available in the toolbar and the Flash menu system.

The Actions panel provides more options than are available in the Script window. This is because these additional options are useful in the context of creating ActionScript embedded into a Flash document, but not when writing external ActionScript files.

The options that are available in the Script window and Actions panel are discussed in About the Actions panel and Script window toolbars.

The following options are available from the Actions panel pop-up menu, and from a variety of menus in the Script window.

NOTE : Some of the following options are found in the Actions panel only. These features are marked Actions panel only.

Reload code hints Actions panel only. If you customize the Script assist mode by writing custom methods, you can reload code hints without restarting Flash 8.

Pin script Actions panel only. Pins (locks in place) the script currently displayed in the Script pane.

Close script Actions panel only. Closes the currently open script.

Close all scripts Actions panel only. Closes all currently open scripts.

Go to line Locates and highlights the specified line in the Script pane.

Find and replace Finds and replaces text within your scripts in the Script pane.

Find again Repeats the find action for the last search string that you entered in the Find tool.

Import script Allows you to import a script file (ActionScript) into the Script pane.

Export script Exports the current script to an external ActionScript (AS) file.

Esc shortcut keys Quickly enter common language elements and syntax structures into your scripts. For example, when you press Esc+g+p in the Script pane, the gotoAndPlay() function is inserted into the script. When you select the Esc Shortcut Keys option from the Actions panel pop-up menu, all of the available Escape shortcut keys appear in the Actions toolbox.

Hidden characters View hidden characters in your script. Hidden characters are spaces, tabs, and line breaks.

Line numbers Displays line numbers in the Script pane.

Preferences Actions panel only. Displays the ActionScript preferences dialog box.

Word wrap To wrap the lines of your script that exceed the current size of the Script window, select Word Wrap from the Actions panel pop-up menu. When you are using the Script window, select Word Wrap from the View menu. For more information, see Using line numbers and word wrap.

Group Actions with Actions panel only. Allows you to group the Actions panel (which includes the Actions toolbox and the Script navigator) with other panels within the Flash authoring environment.

In addition, the Actions panel pop-up menu includes the Print, Help, and panel resizing commands.

 

About ActionScript preferences

TOP

Whether you edit code in the Actions panel or the Script window, you can set and modify a single set of preferences. You can, for example, control automatic indentation, code hinting and coloring, and a number of other basic code editing features.

To access ActionScript preferences:

  1. To access ActionScript preferences in a FLA file with the Actions panel, select Preferences from the pop-up menu, or Edit > Preferences (Windows) or Flash > Preferences (Macintosh), and click ActionScript in the Category list.

  2. To access ActionScript preferences in the Script window, select Edit > Preferences and then click ActionScript (Windows) or Flash > Preferences and then click ActionScript (Macintosh).

The following image shows the ActionScript settings you can change in Flash 8.

You can set the following 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 in ActionScript preferences.

Tab size Specifies the number of characters a new line is offset by when automatic indentation is turned on.

Code hints Enables code hinting in the Script pane. For more information about using code hinting, see About code hinting in Flash.

Delay Specifies the delay (in seconds) before code hints are displayed.

Font Specifies the font used in the Script pane.

Use dynamic font mapping Checks to ensure that the selected font family has the necessary glyphs to render each character. If not, Flash substitutes a font family that contains the necessary characters. For more information, see Formatting code.

Encoding Specifies the character encoding used when opening, saving, importing, and exporting ActionScript files. For more information, see Importing and exporting scripts.

Reload modified files Lets you select when to see warnings about whether a script file is modified, moved, or deleted. Select between Always, Never, or Prompt.

  • Always No warning is displayed when a change is detected, and the file is automatically reloaded.

  • Never No warning is displayed when a change is detected, and the file remains in the current state.

  • Prompt (Default) Warning is displayed when a change is detected, and you can choose whether or not to reload the file.

When building applications that involve external script files, this feature helps you avoid overwriting a script that a team member has modified since you opened the application, or 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 the colors for code coloring in your scripts. With code coloring enabled, you can select the colors to be displayed in the Script pane.

Language Opens the ActionScript Settings dialog box.

 

About triggering code hints

TOP

When you work in the Actions panel or Script window, Flash can detect what action you are entering and display a code hint. The two different styles of code hint are a tooltip that contains the complete syntax for that action, and a pop-up menu that lists possible method or property names (sometimes referred to as a form of code completion). A pop-up menu appears for parameters, properties, and events when you use strict typing or naming for your objects, as discussed in the rest of this section.

Code hints sometimes appear if you double-click an item in the Actions toolbox or click Add (+) in the Actions panel or Script window toolbar to add actions to the Script pane. For information on using code hints when they appear.

NOTE : Code hinting is enabled automatically for native classes that don't require you to create and name an instance of the class, such as Math, Key, Mouse, and so on.

To ensure that code hints are enabled, the Code Hints options must be selected in the ActionScript Preferences dialog box

 

Using code hints

TOP

Code hints are enabled by default. By setting preferences, you can disable code hints or determine how quickly they appear. When code hints are disabled in preferences, you can still display a code hint for a specific command.

To specify settings for automatic code hints, do one of the following:

  • In the Actions panel or Script window, select Edit > Preferences (Windows) or Flash > Preferences (Macintosh), click ActionScript in the Category list, and then enable or disable Code Hints.

  • In the Actions panel, select Preferences from the pop-up menu (at the upper-right of the Actions panel) and enable or disable Code Hints in the ActionScript preferences.

If you enable code hints, you can also specify a delay in seconds before the code hints should appear. For example, if you are new to ActionScript, you might prefer no delay, so that code hints always appear immediately. However, if you usually know what you want to type and need hints only when you use unfamiliar language elements, you can specify a delay so that code hints don't appear when you don't plan to use them.

To specify a delay for code hints:

  1. In the Actions panel or Script window, select Edit > Preferences (Windows) or Flash > Preferences (Macintosh) from the main menu.

  2. Click ActionScript in the Category list.

  3. Use the slider to select an amount of delay.

The amount of delay is in seconds.

To work with tooltip-style code hints:

  1. Display the code hint by typing an opening parenthesis [(] after an element that requires parentheses (for example, after a method name, a command such as if or do..while, and so on).

    The code hint appears.

    NOTE : If a code hint doesn't appear, make sure you didn't disable Code Hints in the ActionScript preferences (Edit > Preferences (Windows) or Flash > Preferences (Macintosh) and then click ActionScript in the Category list). To display code hints for a variable or object you created, make sure that you named your variable or object correctly (see About using suffixes to trigger code hints) or that you use strict typing for your variable or object (see About typing objects to trigger code hints).

  2. Enter a value for the parameter.

    If more than one parameter is present, separate the values with commas. For functions or statements, such as the for loop, separate the parameters with semicolons.

    Overloaded commands (functions or methods that can be invoked with different sets of parameters) such as gotoAndPlay() or for display an indicator that lets you select the parameter you want to set. Click the small arrow buttons or press Control+Left Arrow and Control+Right Arrow to select the parameter.

  3. To dismiss the code hint, do one of the following:

    • Type a closing parens [)].

    • Click outside the statement.

    • Press Escape.

To work with menu-style code hints:

  1. Display the code hint by typing a period after the variable or object name.

    The code hint menu appears.

    NOTE : If a code hint doesn't appear, make sure you didn't disable code hints in the ActionScript preferences (Edit > Preferences (Windows) or Flash > Preferences (Macintosh) and then click ActionScript in the Category list). To display code hints for a variable or object you created, make sure that you named your variable or object correctly or that you used strict typing for your variable or object

  2. To navigate through the code hints, use the Up and Down Arrow keys.

  3. To select an item in the menu, press Enter or Tab, or double-click the item.

  4. To dismiss the code hint, do one of the following:

    • Select one of the menu items.

    • Click above or below the menu window.

    • Type a closing parens [)] if you've already typed an opening parens [(].

    • Press Escape.

To manually display a code hint:

  1. Click in a code location where code hints can appear, such as in the following locations:

    • After the dot (.) following a statement or command, where a property or method must be entered

    • Between parentheses [()] in a method name

  2. Do one of the following:

    • Click Show Code Hint in the Actions panel or Script window toolbar.

    • Press Control+Spacebar (Windows) or Command+Spacebar (Macintosh).

    • If you are working in the Actions panel, select Show Code Hint from the pop-up menu.

 

About typing objects to trigger code hints

TOP

When you use ActionScript 2.0, you can use strict typing for a variable that is based on a built-in class, such as Button, Array, and so on. If you do so, the Script pane displays code hints for the variable. For example, suppose you type the following code:

var names:Array = new Array();

names.

As soon as you type the period (.), Flash displays a list of methods and properties available for Array objects in a pop-up menu, because you have typed the variable as an array.

 

About using suffixes to trigger code hints

TOP

If you use ActionScript 1 or you want to display code hints for objects you create without strictly typing them (see About typing objects to trigger code hints), you must add a special suffix to the name of each object when you create it. For example, the suffixes that trigger code hinting for the Array class and the Camera class are _array and _cam, respectively. For example, if you type the following code

var my_array = new Array();

var my_cam = Camera.get();

you can type either of the following (the variable name followed by a period):

my_array.

my_cam.

Code hints for the Array and Camera objects will appear.

For objects that appear on the Stage, use the suffix in the Instance Name text box in the Property inspector. For example, to display code hints for MovieClip objects, use the Property inspector to assign instance names with the _mc suffix to all MovieClip objects. Then, whenever you type the instance name followed by a period, code hints appear.

Although suffixes are not required for triggering code hints when you use strict typing for an object, using suffixes consistently helps make your code understandable.

The following table lists the suffixes required for support of automatic code hinting:

Object type

Variable suffix

Array

_array

Button

_btn

Camera

_cam

Color

_color

ContextMenu

_cm

ContextMenuItem

_cmi

Date

_date

Error

_err

LoadVars

_lv

LocalConnection

_lc

Microphone

_mic

MovieClip

_mc

MovieClipLoader

_mcl

PrintJob

_pj

NetConnection

_nc

NetStream

_ns

SharedObject

_so

Sound

_sound

String

_str

TextField

_txt

TextFormat

_fmt

Video

_video

XML

_xml

XMLNode

_xmlnode

XMLSocket

_xmlsocket

 

About using comments to trigger code hints

TOP

You can also use ActionScript comments to specify an object's class for code hints. The following example tells ActionScript that the class of the theObject instance is Object, and so on. If you were to enter mc followed by a period after these comments, code hints that display the list of MovieClip methods and properties would appear. If you were to enter theArray followed by a period, a menu that displays a list of Array methods and properties would appear, and so on.

// Object theObject;

// Array theArray;

// MovieClip theMc;

However, Macromedia recommends that instead of this technique, you use strict data typing  or suffixes because these techniques enable code hints automatically and make your code more understandable.

 

Formatting code

TOP

You can specify settings to determine if your code is formatted and indented automatically or manually. In addition, you can select whether to use dynamic font mapping, which ensures that the correct fonts are used when working with multilingual text.

To set format options:

  1. In the Actions panel, select Preferences from the pop-up menu (at the upper right of the Actions panel). In the Preferences dialog box, select Auto Format.

    Alternatively, in the Script window, select Edit > Preferences (Windows) or Flash > Preferences (Macintosh). In the Preferences dialog box, select Auto Format.

  2. Select any of the Auto Format options.

    To see the effect of each selection, look in the Preview pane.

After you set Auto Format options, your settings are applied automatically to code you write, but not to existing code; you must apply your settings to existing code manually. You must manually format code that was formatted using different settings, code that you imported from another editor, and so on.

To format code according to Auto Format settings, do one of the following:

  • Click the Auto Format button in the Actions panel or Script window toolbar.

  • In the Actions panel, select Auto Format from the pop-up menu.

  • Press Control+Shift+F (Windows) or Command+Shift+F (Macintosh).

  • In the Script window, select Tools > Auto Format.

To use dynamic font mapping:

  • To turn dynamic font mapping on or off, select or deselect Use dynamic font mapping in the Preferences dialog box.

Dynamic font mapping is turned off by default because it increases performance time when you are scripting. If you are working with multilingual text, turn on dynamic font mapping because it helps to ensure that the correct fonts are used.

To use automatic indentation:

  • To turn automatic indentation on or off, select or deselect Automatic indentation in the Preferences dialog box.

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 in ActionScript preferences.

In your scripts, you can indent a line by selecting the line and pressing Tab. To remove the indent, select the line and press Shift+Tab.

 

Using syntax highlighting

TOP

In ActionScript, as in any language, syntax is the way elements are put together to create meaning. If you use incorrect ActionScript syntax, your scripts cannot work.

When you write scripts in Flash Basic 8 and Flash Professional 8, commands that are not supported by the version of the player you are targeting appear in yellow in the Actions toolbox. For example, if the Flash Player SWF file version is set to Flash 7, ActionScript that is supported only by Flash Player 8 appears in yellow in the Actions toolbox. (For information on setting the Flash Player SWF file version, see Setting publish options for the Flash SWF file format in Using Flash.

You can also set a preference to have Flash color-code parts of your scripts as you write them, which brings attention to typing errors. For example, suppose you set the Syntax coloring preference to make keywords appear in deep blue. While you type code, if you type var, the word var appears in blue. However, if you mistakenly type vae, the word vae remains black, which shows that you made a typing error. For information on keywords, see About keywords.

To set preferences for syntax coloring as you type, do one of the following:

  • Select Edit > Preferences (Windows) or Flash > Preferences (Macintosh), click ActionScript in the Category list, and specify Syntax coloring settings.

  • In the Actions panel, select Preferences from the pop-up menu (at the upper right of the Actions panel) and specify Syntax coloring settings in ActionScript preferences.

  • With the mouse pointer focused in the Script pane, press Control-U (Windows) or Command-U (Macintosh).

You can change the color settings for keywords, comments, identifiers, and strings.

 

Using line numbers and word wrap

TOP

You can select whether to view line numbers and whether to wrap long lines of code. Typically, you should enable line numbers and word wrap to make editing code much easier. Line numbers make code easier to scroll and parse when you're editing or modifying the code. Word wrap helps you avoid horizontally scrolling long lines of code (especially when you work in the authoring environment, or at low screen resolutions).

To enable or disable line numbers, do one of the following:

  • In the Actions panel, select Line Numbers from the pop-up menu.

  • In the Script window, select Tools > Line Numbers.

  • Press Control+Shift+L (Windows) or Command+Shift+L (Macintosh).

To enable or disable line word wrap, do one of the following:

  • In the Actions panel, select Word Wrap from the pop-up menu.

  • In the Script window, select Tools > Word Wrap.

  • Press Control+Shift+W (Windows) or Command+Shift+W (Macintosh).

 

Using Escape shortcut keys

TOP

You can add many elements to a script by using Escape shortcut keys (pressing the Escape key, and then two other keys).

NOTE : These shortcuts are different from the keyboard shortcuts that initiate certain menu commands.

For example, if you are working in the Script pane and press Escape+d+o, the following code is placed in your script:

do {

} while ();

The insertion point is placed immediately following the word while, so you can begin typing your condition. Similarly, if you press Escape+c+h, the following code is placed in your script, and the insertion point is placed between the parentheses [()], so you can begin typing your condition:

catch () {

}

If you want to learn (or be reminded) about which commands have Escape shortcut keys, you can show them next to elements in the ActionScript toolbox.

To show or hide Escape shortcut keys:

  • From the Actions panel pop-up menu, select or deselect Esc Shortcut Keys.

    Escape shortcut keys appear next to elements in the ActionScript toolbox.

 

Showing hidden characters

TOP

As you write and format ActionScript code, you will enter spaces, tabs, and line breaks into your script. These of course are good and necessary to the visual organization of your code. However, the Flash compiler generates errors if it encounters double-byte spaces that are not part of a string value. Showing hidden characters in the Script pane allows you to see and then remove double-byte spaces.

The following symbols are used to display each hidden character:

 

single-byte space

.

double-byte space

l

tab

>>

line break

 

To show hidden characters, do one of the following:

  • Select Hidden Characters from the pop-up menu.

  • Press Control+Shift+8 (Windows) or Command+Shift+8 (Macintosh).

With hidden characters shown, the Script pane looks like this:

 

Using the Find tool

TOP

The Find tool allows you to find and optionally replace text string in your scripts. You may replace the first or all occurrences of the text in your script. You may also match the case of the text.

To find text in a script:

  1. From the Actions panel or Script window toolbar, select the Find tool or press Control+F (Windows) or Command+F (Macintosh).

  2. Enter the search string that you want to locate in the script.

  3. Click Find Next.

    If the text or characters are present in the script, the words or characters will be highlighted in the Script pane.

To find and replace text in a script:

  1. From the Actions panel or Script window toolbar, click the Find tool or press Control+F (Windows) or Command+F (Macintosh).

  2. Enter the search string that you want to locate and replace in the script.

  3. In the Replace text box, enter the new string.

  4. Click Find Next.

    If the string is present in the script, it is highlighted.

  5. Click Replace to replace the string, or click Replace All to replace all occurrences of the string.

After you've entered a search string in the Find tool, you can repeat the search by selecting Find Again from the pop-up menu.

 

Checking syntax and punctuation

TOP

To determine whether the code you wrote performs as planned, you need to publish or test the file. However, you can do a quick check of your ActionScript code without leaving the FLA file. Syntax errors are listed in the Output panel. You can also check to see if a set of parentheses, curly braces, or brackets around a block of code is balanced.

When you check syntax, the current script is checked. If the current script calls ActionScript 2.0 classes, those classes are compiled and their syntax is also checked. Other scripts that might be in the FLA file are not checked.

To check syntax, do one of the following:

  • Click Check Syntax in the Actions panel or Script window toolbar.

  • In the Actions panel, select Check Syntax from the pop-up menu.

  • Select the Script pane (so it has focus), and then press Control+T (Windows) or Command+T (Macintosh).

NOTE : If you click Check Syntax in an external ActionScript 2.0 class file in the Script window, the global class path affects this process. Sometimes you will generate errors--even if the global class path is set correctly--because the compiler is not aware that this class is being compiled.

To check for punctuation balance, do one of the following:

  • Click between braces ({}), brackets ([]), or parentheses [()] in your script.

  • For Windows, press Control+' (single quote), or for Macintosh, press Command+' (single quote) to highlight the text between braces, brackets, or parentheses.

The highlighting helps you check that opening punctuation has corresponding closing punctuation.

 

Importing and exporting scripts

TOP

You may both import a script into the Actions panel or Script window and export your scripts to external ActionScript files. Both can be useful for sharing code between different Flash applications and development teams.

To import an external AS file:

  • To import an external script into a script that you're working on in the Script pane, place the insertion point where you want the first line of the external script to be located and then do either of the following:

    • In the Actions panel, select Import Script from the pop-up menu or press Control+Shift+I (Windows) or Command+Shift+I (Macintosh).

    • In the Script window, select Import Script from the File menu or press Control+Shift+I (Windows) or Command+Shift+I (Macintosh).

You can export a script from the Actions panel. When you use the Script window, exporting is unnecessary because you can instead save the AS file.

To export a script from the Actions panel:

  1. Select the script to export and then select Export Script from the pop-up menu or press Control+Shift+X (Windows) or Command+Shift+X (Macintosh).

    The Save As dialog box appears.

  2. Save the ActionScript (AS) file.

Flash supports a number of different character encoding formats (including Unicode) and you may specify which format to use when importing and exporting scripts.

 

About Actions panel features

TOP

The following features are only available in the Actions panel. These features are not available in the Script window. Even though the Actions panel has all the features of the Script window, the Script window is used for a different functionality. The Actions panel has to support some FLA file-related functionality, which you'll read about in the following sections. For features that are available in both the Script window and the Actions panel.

 

About Script Assist

TOP

Script Assist prompts you to enter the elements of a script, helping you to more easily add simple interactivity to your Flash SWF file or application. Script Assist mode is ideal for users who either aren't comfortable writing their own scripts or who just appreciate the convenience the tool provides.

Used in conjunction with the Actions panel, Script Assist prompts you to select options and enter parameters. For example, instead of writing a new script, you can select a language element from the Actions toolbox (or the Add (+) command on the toolbar), drag it into the Script pane, and then use Script Assist to help you complete the script.

In the example below, the gotoAndPlay function was added to the Script pane. Script Assist displays all of the prompts needed to use this ActionScript function--in this case, the scene name, the type, and the frame number.

 

Pinning scripts in the Actions panel

TOP

If you don't centralize your code within a FLA file in one location (discussed in Organizing ActionScript code) or if you're using behaviors (see About behaviors), you can pin multiple scripts in the Actions panel to make it easier to move among them. To pin a script means that you can keep the location of the code open in the Actions panel, and easily click between each open script.

In the following figure, the script associated with the current location on the timeline is on Frame 1 of the layer named Cleanup. (The tab at the far left always follows your location along the timeline.) That script is also pinned (it is shown as the right-most tab). Two other scripts are pinned: one on Frame 1 and the other on Frame 15 of the layer named Intro. You can move among the pinned scripts by clicking on the tabs or by using keyboard shortcuts, such as Control+Shift+. (period). Moving among pinned scripts does not change your current position on the timeline. As you can see in the following figure, multiple scripts are open in the Actions panel, and you can click each tab to move between the scripts.

 

TIP : If the content in the Script pane doesn't change to reflect the location that you select on the timeline, the Script pane is probably showing a pinned script. Click the left tab at the lower left of the Script pane to show the ActionScript associated with your location along the timeline.

To pin a script:

  1. Position your mouse pointer on the Timeline so the script appears in a tab at the lower left of the Script pane in the Actions panel.

  2. Do one of the following:

    • Click the pushpin icon to the right of the tab.

    • Right-click (Windows) or Control-click (Macintosh) on the tab, and select Pin Script.

    • Select Pin Script from the pop-up menu (at the upper right of the Actions panel).

    • With the mouse pointer focused in the Script pane, press Control+= (equal sign) in Windows or Command+= on the Macintosh.

To unpin one or more scripts, do one of the following:

  • If a pinned script appears in a tab at the lower left of the Script pane in the Actions panel, click the pushpin icon on the right of the tab.

  • Right-click (Windows) or Control-click (Macintosh) on a tab, and select Close Script or Close All Scripts.

  • Select Close Script or Close All Scripts from the pop-up menu (at the upper right of the Actions panel).

  • With the mouse pointer focused in the Script pane, press Control+-(minus sign) in Windows or Command+- on Macintosh.

To use keyboard shortcuts with pinned scripts:

  • You can use the following keyboard shortcuts to work with pinned scripts:

Action

Windows shortcut key

Macintosh shortcut key

Pin script

Control+= (equal sign)

Command+=

Unpin script

Control+- (minus sign)

Command+-

Move focus to tab on the right

Control+Shift+. (period)

Command+Shift+.

Move focus to tab on the left

Control+Shift+, (comma)

Command+Shift+,

Unpin all scripts

Control+Shift+- (minus)

Command+Shift+-

Inserting target paths

TOP

Many of the actions that you create in your script will affect movie clips, buttons, and other symbol instances. To apply actions to instances on a timeline, you set a target path--the address of the instance you want to target. You can set either an absolute or relative target path.

The Target Path tool, which is available in the Actions panel, prompts you to enter the target path for the selected action in your script.

To insert a target path:

  1. Select and position the pointer in an action in your script.

  2. Click Target Path on the Actions panel toolbar.

    The Insert Target Path dialog box appears.

  3. Do one of the following:

    • Manually enter the path to the target instance.

    • Select the target from the list of available targets.

  4. Select either the Absolute or Relative path option.

  5. Click OK.

    The path is appended to the action.

 

About behaviors

TOP

Behaviors are predefined ActionScript functions that you can attach to objects in your Flash document without having to create the ActionScript code yourself. Behaviors provide you with prewritten ActionScript functionality, such as frame navigation, loading of external SWF files and JPEGs, controlling the stacking order of movie clips, and movie clip dragging.

You can use behaviors as a convenience when building your Flash application--as a way to avoid having to write ActionScript, or conversely as a way to learn how ActionScript works in certain situations.

Behaviors are available to you only when you are working in a Flash document, not in an external script file. Typically, you select a triggering object in your document, a movie clip or a button, select Add on the Behaviors panel to display the available behaviors, and then select the behavior you want, as shown in the following example:

The behavior is added to the object and is displayed in the Actions panel.

 

About ActionScript publish settings

TOP

You can edit ActionScript in two ways. You can edit ActionScript that is embedded into a Flash document by using the Actions panel. Or you can edit ActionScript that is in a separate script file, external to the Flash document, using the Script window. Because the Actions panel and the Script window are essentially two different views that use the same ActionScript editor, ActionScript settings and preferences within Flash apply to both views.

You edit the Flash document's publish settings to change the version of ActionScript that will be used when the document is published. You can also set the classpath for the current document by passing the global ActionScript classpath.

 

Modifying ActionScript publish settings

TOP

When you publish a Flash document, the ActionScript version is set to 2.0 by default and the classpath is inherited from the global classpath setting. If you need to change the version of ActionScript or to specify a document-level classpath, you can do so by editing the publish settings.

To change the ActionScript version:

  1. Select File > Publish Settings and then select the Flash tab.

  2. Select the ActionScript version from the pop-up menu.

ActionScript 2.0 is selected by default. If you write your scripts in ActionScript 1.0 instead of 2.0, change this setting before you publish your Flash document.

The ActionScript 2.0 compiler compiles all ActionScript 1.0 code, with the following exception: the slash (/) syntax used to indicate movie clip paths (for example, parentClip/testMC:varName= "hello world") generates compilation errors if you select ActionScript 2.0 as the ActionScript version. To resolve this problem, either rewrite your code using dot (.) notation in place of slashes, or select the ActionScript 1.0 compiler.

 

Modifying the classpath

TOP

When you use ActionScript 2.0, you can also set a document-level classpath. This is useful when you create your own classes and you want to override the global ActionScript classpath that is set in the ActionScript preferences.

Changing the classpath in the publish settings only applies to the current Flash file.

You can use the Preferences dialog box to modify the global classpath. To modify the document-level classpath setting, you use the Publish Settings dialog box for the FLA file. In both cases, you can add absolute directory paths (for example, C:/my_classes) and relative directory paths (for example, ../my_classes or ".").

To modify the global classpath:

  1. Select Edit > Preferences (Windows) or Flash > Preferences (Macintosh) to open the Preferences dialog box.

  2. Click ActionScript in the Category list, and then click ActionScript 2.0 Settings.

  3. Do one of the following:

    • To add a directory to the classpath, click Browse to Path, browse to the directory you want to add, and click OK.

      Alternatively, click Add New Path (+) to add a new line to the Classpath list. Double-click the new line, type a relative or absolute path, and click OK.

    • To edit an existing classpath directory, select the path in the Classpath list, click Browse to Path, browse to the directory you want to add, and click OK.

      Alternatively, double-click the path in the Classpath list, type the desired path, and click OK.

    • To delete a directory from the classpath, select the path in the Classpath list and click Remove from Path.

      NOTE : Do not delete the absolute global classpath (see Global and document-level classpaths). Flash uses this classpath to access built-in classes. If you accidentally delete this classpath, reinstate it by adding $(LocalData)/Classes as a new classpath.

To modify the document-level classpath:

  1. Select File > Publish Settings to open the Publish Settings dialog box.

  2. Click the Flash tab.

  3. Click Settings next to the ActionScript Version pop-up menu.

  4. Do one of the following:

    • To add a directory to the classpath, click Browse to Path, browse to the directory you want to add, and click OK.

    • Alternatively, click Add New Path (+) to add a new line to the Classpath list. Double-click the new line, type a relative or absolute path, and click OK.

    • To edit an existing classpath directory, select the path in the Classpath list, click Browse to Path, browse to the directory you want to add, and click OK.

    • Alternatively, double-click the path in the Classpath list, type the desired path, and click OK.

    • To delete a directory from the classpath, select the path in the Classpath list, and click Remove from Path.

 

Configuration files that install with Flash 8

TOP

When you install Flash Basic 8 or Flash Professional 8, several ActionScript-related configuration folders and files are placed on your system. You might use these files to make certain configurations to the authoring environment. As always, modify carefully and save a back up of files that you modify.

ActionScript classes folder Contain all of the ActionScript classes (AS files) that are included in Flash Professional 8 or Flash Basic 8. Typical paths to this folder are as follows:

  • Windows: Hard Disk\Documents and Settings\user\Local Settings\Application Data\Macromedia\Flash 8\language\Configuration\Classes.

  • Macintosh: Hard Disk/Users/user/Library/Application Support/Macromedia/Flash 8/language/Configuration/Classes.

The Classes folder is organized into folders that contain directories that contain the classes for Flash Player 7 (FP7) and Flash Player 8 (FP8). It also contains a directory for the mx package (mx), that's used in both players and ASO files (aso). For more information on ASO files. For more information on the organization of this directory, see the readme file in the Classes folder.

Include classes folder Contain all of the global ActionScript include files and is located in:

  • Windows: Hard Disk\Documents and Settings\user\Local Settings\Application Data\Macromedia\Flash 8\language\Configuration\Include.

  • Macintosh: Hard Disk/Users/user/Library/Application Support/Macromedia/Flash 8/language/Configuration/Include.

ActionsPanel.xml configuration file Includes the configuration file for ActionScript code hinting and is located in:

  • Windows: Hard Disk\Documents and Settings\user\Local Settings\Application Data\Macromedia\Flash 8\language\Configuration\ActionsPanel\ActionScript_1_2.

  • Macintosh: Hard Disk/Users/user/Library/Application Support/Macromedia/Flash 8/language/Configuration/ActionsPanel/ActionScript_1_2.

AsColorSyntax.xml configuration file The configuration file for ActionScript code color syntax highlighting; located in:

  • Windows: Hard Disk\Documents and Settings\user\Local Settings\Application Data\Macromedia\Flash 8\language\Configuration\ActionsPanel\.

  • Macintosh: Hard Disk/Users/user/Library/Application Support/Macromedia/Flash 8/language/Configuration/ActionsPanel.

 

Copyright ADOBE - All Rights Reserved Worldwide

 

 

More Topics:

Working with Flash Documents

How to work in Flash WorkSpace

Working with Projects in Flash

Process to Build your First Application in Flash

Using Symbols, Instances and Library Assets in Flash

How to Build Video Player in Flash

How to Work with Color, Strokes and Fills in Flash

How to Create Document in Flash

What is Vector and Bitmap Graphics in Flash

How to Create a Banner in Flash, Part 1

How to Work with Text in Flash

How to Create a Banner in Flash, Part 2

How to Use Imported Artwork in Flash

How to Create a Banner in Flash, Part 3

How to Work with Graphic Objects in Flash

How to Work with Layers in Flash

How to Use Filters and Blends

Working with Graphics in Flash

What is Accessibility Features in Flash

How to Create Motion (Shape Tween & Motion Tween) in Flash

How to Create an Application in Flash

What is Masking in Flash

How to Work with Video in Flash

How to Use Layout Tools in Flash

What are Behaviors in Flash

How to Work with Sound in Flash

How to Create Symbols and Instances in Flash

What is ActionScript in Flash

How to Write ActionScript With Script Assist in Flash

How to Add Button Animation and Navigation in Flash

What is Data Integration in Flash

How to Work with Screens

How to Create a Presentation with Screens

What is Extending Flash

How to Create Multilanguage Text in Flash

How to Create Graphics: Draw in Flash

What is Flash Lite

Ways of Data Integration

How to Create Graphics: Create a Timeline Animation in Flash

Getting Started with Flash Lite in Flash

How to Publish Flash Documents

How to Create Graphics: Making Animations with Easing

Learning Flash Lite 1.X ActionScript in Flash

How to Export Flash Content and Images from Flash

How to Create Graphics: Applying Gradients in Flash

Process of Writing and Editing ActionScript 2.0 in Flash

How to Create Accessible Content in Flash

How to Create Graphics: Apply Graphic Filters and Blends

What is Data and Data Types in Flash

Process of Printing from SWF Files in Flash

Using ActionScript: How to Use Script Assist mode in Flash

Learn Syntax and Language Fundamentals in Flash

How to Create E-learning Content in Flash

Using ActionScript: How to Write Scripts in Flash

Working with Functions and Methods in Flash

Process of Using Templates in Flash

Using ActionScript: Process of Adding Interactivity in Flash

What are Classes in Flash

Control Tag Summary of XML to UI in Flash

Using ActionScript: How to Create a Form with Conditional Logic and Send Data in Flash

What is Inheritance in Flash

What is Data Integration: Overview

Using ActionScript: How to Work with Objects and Classes in Flash

Overview on Interfaces in Flash

What is Data Integration: Using XML for a Timesheet

How to Work with Text and Strings in Flash

How to use Handling Events in Flash

What is Data Integration: Using XUpdate to Update the Timesheet

Learning Animation, Filters and Drawings in Flash

How to Work with Movie Clips in Flash

How to Create Interaction with ActionScript in Flash

How to Work with Images, Sound, and Video in Flash

How to Work with External Data in Flash

What is Security in Flash

How to Debug Applications in Flash

List of Error Messages in Flash

Using Object-Oriented Programming with ActionScript 1.0 in Flash

How to Write Scripts for Earlier Versions of Flash Player in Flash

List of all Keyboard Keys and Key Code Values for using in Flash

Terminology

Introduction to Components in Flash

What are Components in Flash

How to Create an Application with Components

How to Work with Components in Flash

How to Handle Component Events in Flash

How to Customize Components in Flash

How to Create Components in Flash

What is Collection Properties in Flash