A New Version of ActionScript

     

ActionScript has been massively overhauled, giving birth to a brand-new version, ActionScript 2 (AS2), which implements object-oriented programming (OOP) in a more standard way than before.

For more on object-oriented programming (OOP), see "Understanding Object-Oriented Languages," page 446 , in Chapter 19, "Introduction to ActionScript."


This section provides a high-level overview of these changes. See the chapters on ActionScript for details.

AS2 makes it easier to develop and debug object-oriented programs, especially for programmers familiar with other object-oriented languages, such as Java. Conversely, if you're new to programming, learning AS2 will give you more of a head start on learning other object-oriented languages.

One major new feature is strict data typing. When you create a variable, strict typing lets you declare that the variable can represent only a particular type of object, such as a number, a date, or a text string. Then, when you test your program, if you use a variable improperly ”for instance, you use a number in a context that requires a text string ”you get an error message. (AS2 does not insist that you declare all variable types, however.)

You can also use strict data typing and still publish for the Flash Player 6. Data types are checked only when you compile, not at runtime, so this feature is fundamentally independent of the Flash Player.

Flash MX 2004 doesn't force you to use any new ActionScript features. You can continue to code just as you did before, as long as you publish for the Flash Player 6. Macromedia is to be congratulated for finding a way to implement such sweeping changes in ActionScript and yet maintain perfect backward compatibility for existing scripts.

If you want to publish for Flash Player 7, you may need to modify your existing scripts. The modifications are conceptually minor, mainly involving case sensitivity and new reserved words.

One issue is that if you publish for Flash Player 7, ActionScript is case sensitive. Previously, ActionScript saw myVar and MyVar as the same thing, but no more.

There are also some new reserved words, such as ContextMenu , Error , PrintJob , and throw . In ActionScript 1, you are free to use these words as you wish. In AS2 they are part of the language, so you shouldn't use them for your own purposes. New reserved words include class , extends , implements , interface , intrinsic , dynamic , static , public , private , get , set , and import .



Using Macromedia Studio MX 2004
Special Edition Using Macromedia Studio MX 2004
ISBN: 0789730421
EAN: 2147483647
Year: N/A
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net