< Day Day Up > |
ActionScript 1.0 is based on the ECMAScript 3 standard (as is JavaScript 1.5), whereas ActionScript 2.0 is based on the emerging ECMAScript 4 standard (as is the theoretical JavaScript 2.0). As we learned in the Preface, under "ActionScript 2.0 Versus ActionScript 1.0," this common heritage gives the two versions a strong family resemblance; they share the same syntax for most non-OOP features, such as loops , conditionals, and operators. Although ActionScript 2.0 is now the preferred version of ActionScript, ActionScript 1.0 syntax continues to be fully supported by Flash Player 7 and is not deprecated. As we'll see shortly, you can author either ActionScript 1.0 or ActionScript 2.0 in Flash MX 2004 and Flash MX Professional 2004 (but you cannot author ActionScript 2.0 in Flash MX). With a few minor exceptions, noted throughout the text, ActionScript 2.0 code is also backward compatible with Flash Player 6. However, ActionScript 2.0 is not compatible with older versions such as Flash Player 5 or Flash Player 4. If you're an ActionScript 1.0 programmer, you can think of ActionScript 2.0 as a syntactic fa §ade over ActionScript 1.0. That is, both ActionScript 2.0 and ActionScript 1.0 compile to the same .swf bytecode (with a few minor additions for ActionScript 2.0). To the Flash Player, at runtime, there's effectively no difference between ActionScript 1.0 and ActionScript 2.0 (barring the aforementioned minor additions). For example, once an ActionScript 2.0 class, such as Rectangle , is compiled to a .swf file, it exists as a Function object at runtime, just as an older ActionScript 1.0 function declaration used as a class constructor would. Similarly, at runtime, an ActionScript 2.0 Rectangle instance ( r ) is given a _ _proto_ _ property that refers to Rectangle.prototype , again making it look to the Flash Player just like its ActionScript 1.0 counterpart . But for the most part, you don't need to worry about these behind-the-scenes compiler and runtime issues. If you're moving to ActionScript 2.0 (and I think you should!), you can permanently forget ActionScript 1.0's prototype-based programming. In fact, most ActionScript 1.0 techniques for dynamically manipulating objects and classes at runtime are considered bad practice in ActionScript 2.0, and will actually lead to compiler errors when mixed with ActionScript 2.0 code. But never fear, this book highlights problematic ActionScript 1.0 practices and show you how to replace them with their modern ActionScript 2.0 counterparts. 1.4.1 Setting a Movie's ActionScript Version and Player VersionFlash 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:
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 ActionScript Version.
When the ActionScript version is set to ActionScript 1.0, the following changes take effect:
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:
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
1.4.2 Changes to ActionScript 1.0 in Flash Player 7In a Flash Player 7-format .swf file running in Flash Player 7, some ActionScript 1.0 code behaves differently than it does in Flash Player 6. These changes bring Flash Player 7 closer to full ECMAScript 3 compliance. Specifically:
The preceding changes affect you only when you are updating a Flash Player 6-format movie to a Flash Player 7-format movie in order to use a feature unique to Flash Player 7. That is, if you upgrade your movie, you must test and possibly modify your code to make sure that it operates the same in Flash Player 7 format as it did in Flash Player 6 format. If you do not need Flash Player 7 features in your movie, you can continue to export it to Flash Player 6 format and it will usually run in Flash Player 7 exactly as it did in Flash Player 6. This last point cannot be emphasized enough.
Of course, any newly created .swf files exported in Flash Player 7 format (and not just those upgraded from Flash Player 6-format .swf files) must obey the new conventions, so keep them in mind moving forward. Remember that these new conventions bring ActionScript in line with other languages such as JavaScript and Java, making it easier to port code to or from other languages. 1.4.3 Flash 4 Slash Syntax Is Not Supported in ActionScript 2.0In Flash 4 and subsequent versions, variables could be referenced with so-called "slash syntax." For example, in Flash 4, the following code is a reference to the variable x on the movie clip ball : /ball:x That syntax generates the following error if you attempt to use it with the ActionScript 2.0 compiler, whether exporting in Flash Player 6 or Flash Player 7 format: Unexpected '/' encountered |
< Day Day Up > |