| • Science | • People | • Locations | • Timeline |
ActionScript achieved something resembling its current syntax (retroactively named ActionScript 1.0) in Flash 5, the first version of Flash to be thoroughly programmable. Flash 6 broadened the power of the programming environment by adding many more built-in functions and allowing more programatic control of movie elements. Flash 7 (MX 2004) introduced ActionScript 2.0, which adds strong typing and object-oriented features such as explicit class declarations, inheritance, interfaces, and encapsulation. ActionScript 1.0 and 2.0 share the same compiled form within Flash SWFs.
Features of the Flash ActionScript implementation that JavaScript programmers may find interesting:
ActionScript code is frequently written directly in the Flash authoring environment, which offers useful reference and powerful aids for syntax checking. In this case, the source code is saved along with the rest of the movie in a .fla file. It is also common for ActionScript code to be imported from external text files via #include statements. In this case, the external files are often given .as extensions, but this is not a universal convention.
The following techniques are not required, but contribute towards more efficient, or at least more easily understandable code.
Naming involves capitalisation of code elements. Function names and variables should begin with a lower-case letter; objects should be capitalized. The first letter of each subsequent word should also be capitalised in both cases.
The Flash code editor features code completion only when variables are named according to a specific format. This involves appending the variable type to the end of the variable name.
| Object type | Suffix string | Example |
|---|---|---|
| String | _str | myString_str |
| Array | _array | myArray_array |
| MovieClip | _mc | myMovieClip_mc |
| TextField | _txt | myTextField_txt |
| Date | _date | myDate_date |
| Sound | _sound | mySound_sound |
| XML | _xml | myXML_xml |
| Color | _color | myColor_color |
Commenting code is always recommended. Comments should document the decisions made while building the code, telling the story of what it attempts to do. A future developer should be able to pickup the logic of the code with the assistance of the comments.
var clicks = 0; // This is a simple comment /* This is a multiline comment. ..... ..... */Some common methods for indicating important comments are:
// :TODO: more work to be done here // :BUG: [bugid] this is a known issue // :KLUDGE: this bit isn't very elegant // :TRICKY: lots of interactions, think twice before modifying