ActionScript
ActionScript is an ECMAScript-based programming language used for controlling Macromedia Flash movies and applications. Since both ActionScript and JavaScript are based on the same ECMAScript syntax, fluency in one easily translates to the other. However, the client model is dramatically different: while JavaScript deals with windows, documents and forms, ActionScript deals with movie-clips, text fields and sounds.ActionScript achieved something resembling it's 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:
- Everything is designed to be asynchronous; callbacks are ubiquitous, but Event objects do not exist.
- The XML implementation has been solid since Flash 5. Flash can send and receive XML asynchronously.
| 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.
Attempt to write event code on a frame rather than on the object itself, unless it is purely a function call.
Information above is summarised from Macromedia's ActionScript Coding Standards. For a more complete explanation, please see the full document.
http://www.macromedia.com/devnet/mx/flash/whitepapers/actionscript_standards.pdf
Commenting code
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
Timeline layout
Scoping variables
_parent.myVar.blah = 100; // Use relative addressing like this
_root.myClip = 200; // Avoid absolute addressing as much as possible
_global.myVar = 300; // _global variables are available to all movies within the player
Keep actions together
Avoid attaching code to Movie Clips or buttons
// CODE ON BUTTON - Not Recommended
on (release) {
play();
}
// CODE ON FRAME - Recommended
myButton.onRelease = function() {
play();
}
Source
External links
See Also