ActionScript 2.0 Overview - Setting a Movie’s ActionScript Version and Player Version
(Page 6 of 7 )
Flash MX 2004 lets you export .swf files (a.k.a. movies) in a format compatible with specific versions of the Flash Player. Don’t confuse this with the version of the Flash Player the end user has installed (which is beyond your control except for checking their Player version and suggesting they upgrade when appropriate).
To set the version of a .swf file, use the drop-down list under File -> Publish Settings -> Flash -> Version. For maximum compatibility, always set your .swf file’s Flash Player version explicitly to the lowest version required, and no higher. If the .swf file version is higher than the end user’s version of the Flash Player, it might not display correctly, and most code execution will fail.
Setting the version of a Flash movie has the following effects:
- The movie will be compatible with (i.e., playable in) the specified version of the Flash Player (or later versions). In earlier versions, most ActionScript code will either not execute properly or not execute at all.
- The movie will play properly in the most recent version of the Flash Player, even if it uses features that have changed since the specified version was released. In other words, the newest Flash Player will always play older format .swf files properly. For example, ActionScript identifiers in a Flash Player 6–format .swf file playing in Flash Player 7 are not case sensitive, even though identifiers in Flash Player 7–format .swf files are case sensitive. However, there’s one exception: the security changes to the rules of cross-domain data loading in Flash Player 7 affect Flash Player 6–format .swf files in some cases. For details see http://moock.org/asdg/technotes/crossDomainPolicyFiles.
When exporting Flash Player 6– and Flash Player 7–format movies from either Flash MX 2004 or Flash MX Professional 2004, you can tell Flash whether to compile your code as if it is ActionScript 1.0 or ActionScript 2.0. Naturally, you should make this choice at the beginning of development, as you don’t want to rewrite your code at the end. To specify which version of the ActionScript compiler to use when creating a .swf file, use the drop-down list under File -> Publish Settings -> Flash -> Action-Script Version.
Throughout the remainder of the text, this book assumes you are using ActionScript 2.0’s compiler.
When the ActionScript version is set to ActionScript 1.0, the following changes take effect:
- ActionScript 2.0 syntax is not recognized and ActionScript 2.0 features, such as type checking (including post-colon syntax) and error handling, can either cause compiler errors (for Flash Player 6–format movies) or simply fail silently (for Flash Player 7–format movies).
- Flash 4–style “slash syntax” for variables is allowed (but this coding style is deprecated and not recommended).
- Reserved words added in ActionScript 2.0 such as class, interface, and public can be used as identifiers (but this practice makes code difficult to update and is highly discouraged).
The following runtime features of ActionScript 2.0 will not work in .swf files exported to a Flash Player 6–format .swf file, no matter which version of the Flash Player is used:
- Exception handling (see Chapter 10).
- Case sensitivity. (Scripts exported in Flash Player 6–format .swf files are not case sensitive, even in Flash Player 7. But beware! ActionScript 1.0 code in a Flash Player 7–format .swf file is case sensitive when played in Flash Player 7. See Table 1-2.)
- Type casting (see “Runtime Casting Support” in Chapter 3).
Table 1-2 outlines case sensitivity for various possible permutations of the .swf file version and the user’s Flash Player version. Note that runtime case sensitivity is unrelated to the ActionScript compiler version chosen and is dependent only on the format of the exported .swf file and the Flash Player version. In other words, both ActionScript 1.0 and 2.0 are case sensitive when exported in Flash Player 7–format . swf files and played in Flash Player 7. In other cases, code is case insensitive subject to the exceptions cited in the footnotes to Table 1-2. Consult my book ActionScript for Flash MX: The Definitive Guide (O’Reilly) for a full discussion of case sensitivity and its implications in Flash Player 6.
Table 1-2. Runtime case sensitivity support by language, file format, and Flash Player version
Movie compiled as either ActionScript 1.0 or 2.0 and | Played in Flash Player 6 | Played in Flash Player 7 |
Flash Player 6–format .swffile | Case insensitive( a) | Case-insensitive( a) |
Flash Player 7–format .swffile | Not supported( b) | Case-sensitive |
Table notes:
(a) Identifiers (i.e., variable and property names), function names, frame labels, and symbol export IDs are case insensitive in Flash Player 6–format .swf files. However, reserved words such as “if” are case sensitive, even in Flash Player 6.
(b) Flash Player 6 cannot play Flash Player 7–format .swf files.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Changes to ActionScript 1.0 in Flash Player 7 >>
More Flash Articles
More By O'Reilly Media