Your code can be formatted and indented automatically when typing. If you use dynamic font mapping, you ensure that the correct fonts are used for multilingual text.
- Click Auto Format in the Actions panel or Script window toolbar.
- From the panel menu (at the upper-right corner of the Actions panel), select Auto Format.
- Press Control+Shift+F (Windows) or Command+Shift+F (Macintosh).
- In the Script window, select Tools > Auto Format.
-
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 it and pressing Tab. To remove the indent, select the line and press Shift+Tab.
Code comments are parts of code that the ActionScript compiler ignores. A comment line explains what your code is doing, or temporarily deactivates code that you don’t want to delete. Comment a line of code by beginning it with a double slash (//). The compiler ignores all text on that line after the double slash. You can also comment larger blocks of code by placing a slash and asterisk (/*) at the beginning of the block and an asterisk and slash (*/) at the end of the block.
You can type these comment markers manually, or you can use buttons at the top of the Actions panel or Script window to add them.
Opomba:
If there are comments in between the selected lines of text, a line comment will be applied on all selected lines.
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.
To highlight syntax errors, set a color-code for parts of your scripts. For example, suppose you set the syntax coloring preference to make keywords appear in blue. When 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.
Do one of the following:
Select Edit > Preferences (Windows) or Animate > Preferences (Macintosh), click Code Editor in the Category list, and specify Syntax Coloring settings.
With the insertion point in the Script pane, press Control-U (Windows) or Command-U (Macintosh).
Opomba:
When you write scripts in the Actions panel, 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 only Flash Player 8 supports appears in yellow in the Actions toolbox.
On launching Animate, the identifier and keyword lists are read from the resource file and cached. Apart from reading the default lists from the resource, it also scans for additional keywords and identifier list in the Preference folder. It is possible for you to add additional keywords and identifiers by adding ".txt files" in following folders:
C:\Users\<Username>[AppData]\Roaming\Adobe\Animate\13.0[ActionscriptKeywords]\
C:\Users\<UserName>[AppData]\Roaming\Adobe\Animate\13.0[ActionscriptIdentifiers]\
C:\Users\<UserName>[AppData]\Roaming\Adobe\Animate\13.0[JavascriptKeywords]\
C:\Users\<UserName>[AppData]\Roaming\Adobe\Animate\13.0[JavascriptIdentifiers]\
When you edit or modify code, line numbers make code easier to scroll and parse. Word wrap helps you avoid horizontally scrolling long lines of code (especially when you work in the authoring environment, or at low screen resolutions).
- In the Script window, select View > Line Numbers.
- Press Control+Shift+L (Windows) or Command+Shift+L (Macintosh).
- In the Script window, select View > Word Wrap.
- Press Control+Shift+W (Windows) or Command+Shift+W (Macintosh).
Characters such as spaces, tabs, and line breaks are hidden in ActionScript code. You may need to display these characters; for example, you must find and remove double-byte spaces that are not part of a string value, because they cause compiler errors.
Opomba:
To search through text in every script in a Animate document, use the Movie Explorer.
You can do a quick check of your ActionScript code without publishing the FLA file.
When you check syntax, the current script is checked. If the current script calls ActionScript classes, those classes are also checked. Other scripts that might be in the FLA file are not checked.
For ActionScript 2.0 files, Check Syntax runs the code through the compiler, generating syntax and compiler errors.
For ActionScript 3.0 files, Check Syntax generates only syntax errors. To generate compiler errors, such as type mismatches, improper return values, and variable or method name misspellings, you must use the Control > Test command.
- In the Actions panel or Script window, click Check Syntax .
- Click in the Script pane, and then press Control+T (Windows) or Command+T (Macintosh). Clicking or typing in the Script pane gives it the focus. If an object on the Stage has the focus, the Transform panel opens instead.
Opomba:
In an external ActionScript class file in the Script window, the global classpath (AS2) or source path (AS3) affects the syntax check. Even if the global classpath or source path is set correctly, you might generate errors, because the compiler is not aware that this class is being compiled.
You can import a script into the Actions panel or Script window. You can also export your scripts from the Actions panel to external ActionScript files. (When you use the Script window, exporting is unnecessary because you can instead save the AS file.)
If text in your scripts doesn’t look as expected when you open or import a file, change the import encoding preference.
You can set ActionScript preferences to specify the type of encoding to use in imported or exported ActionScript files. UTF‑8 Encoding is 8‑bit Unicode format, which lets you include text in multiple languages in your file; Default Encoding is the encoding supported by the language your system is currently using, also called the traditional code page.
Opomba:
When you use a non-English application on an English system, the Test Movie command fails if any part of the SWF file path has characters that cannot be represented by using the Multibyte Character Sets (MBCS) encoding scheme. For example, Japanese paths, which work on a Japanese system, won’t work on an English system. Be sure to use English-only path names on English systems. All areas of the application that use the Test Movie player are subject to this limitation.
Use the Pin Script feature to 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.
You can also unpin a script or unpin all scripts to unpin a selected script or unpin all scripts from the Actions panel.
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.) The script is also pinned as shown as the rightmost tab. The following two scripts are pinned:
- On Frame 1
- On Frame 15 of the layer named Intro
Use keyboard shortcuts or click the tabs to move among the pinned scripts. Moving among the various pinned scripts does not change your current position on the timeline. If a new script is selected in Action script navigator, focus moves to the first frame ie Frame 1.
Opomba:
If the content in the Script pane does not change to reflect the location you select on the timeline, the Script pane is probably showing a pinned script. Click the current frame tab at the top left of the Script pane to show the script associated with your location along the timeline.
When the insertion point is in the Script pane, use the following keyboard shortcuts to work with pinned scripts.
Action |
Windows |
Macintosh |
---|---|---|
Pin script |
Control+Shift+= (equal sign) |
Command+Shift+= |
Unpin script |
Control+Shift+- (minus sign) |
Command+Shift+- |
Many script actions are meant to affect movie clips, buttons, and other symbol instances. In your code, you can reference symbol instances on a timeline by inserting a target path—the address of the instance you want to target. You can set either an absolute or relative target path. An absolute path contains the entire address of the instance. A relative path contains only the part of the address that is different from the address of the script itself in the FLA file, and will no longer work if the script is moved to another location.
When you work in the Actions panel or Script window, the software can detect what action you are entering and display a code hint. There are two types of code hint: a tooltip that contains the complete syntax for that action, and a pop-up menu that lists possible ActionScript elements, such as method or property names (sometimes referred to as a form of code completion).
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 manually display a code hint for a specific command.
Opomba:
If you cannot display code hints for a variable or object you created in ActionScript 2.0, but code hints are enabled in ActionScript preferences, make sure you named your variable or object with the proper suffix or that you used strict typing for your variable or object.
When you use ActionScript 2.0 and use strict typing for a variable that is based on a built‑in class (such as Button, Array, and so on), the Script pane displays code hints for the variable. For example, suppose you enter the following two lines of code:
var foo:Array = new Array(); foo.
As soon as you enter the period (.), Animate displays a list of methods and properties available for Array objects in a pop-up menu, because you typed the variable as an array.
If you use ActionScript 1.0 or you want to display code hints for objects without strictly typing them, add a suffix to the name of each object when you create it. For example, the suffix that triggers code hinting for the Camera class is _cam. Suppose you type the following code: var my_array = new Array(); var my_cam = Camera.get();
If you then enter my_cam followed by a period, code hints for the Camera object appear.
For objects that appear on the Stage, use the suffix in the Instance Name 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.
var my_array = new Array(); var my_cam = Camera.get();
Opomba:
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.
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 |
You can also use ActionScript comments to specify an object’s class for code hints. In the following example, a comment tells ActionScript that the class of the theObject instance is Object, and so on.
// Object theObject;// Array theArray;// MovieClip theMC;
If you subsequently enter theMC followed by a period, code hints that display the list of MovieClip methods and properties appear. If you enter theArray followed by a period, code hints that display the list of Array methods and properties appear, and so on.
Instead of this technique, however, Adobe recommends that you use strict data typing or suffixes, because these techniques enable code hints automatically and make your code more understandable.
- In the Actions panel or Script window, select Edit > Preferences (Windows) or Animate > Preferences (Macintosh), click Code Editor in the Category list, and then enable or disable Code Hints.
-
For multiple parameters, 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. To select the parameter, click the small arrows or press Control+Left Arrow and Control+Right Arrow.
When you create custom ActionScript 3.0 classes, Animate parses the classes and determines the objects, properties, and methods included in them. Animate can then provide code hinting when you write code that refers to the custom classes. Custom class code completion is automatic for any class that you link to any other code with the import command.
Code hinting allows developers to work faster because they don’t have to remember all the objects, methods, and properties used by the class. Designers can work with classes they did not write themselves because they don’t have to have first hand knowledge of how to work with the class.
Code hinting includes the following:
Code hinting for nested class references
When you write nested references, the continued assistance of code hints is helpful.
Code hinting for “this”
When you type “this” in a class file, you get code hints for that same class.
Code hinting for “new+<space>”
When you type “new+<space>”, Animate displays a list of available classes and packages.
Code hinting for “import”
When you type “import + <space>”, Animate displays a list of all the built-in packages and custom packages.
Code hinting for SWC libraries
When you add a SWC library to the library path or the external library path, Animate enables code hinting for all the classes included in the SWC file.