|< Day Day Up >|
With each new version of ActionScript, Flash developers have pushed the ActionScript language to its limits. To compete in the world of Rich Internet Applications (RIAs), Macromedia has had to take ActionScript to the next level and provide a language that uses a model that enables seasoned application developers to embrace ActionScript. The model also had to provide enhanced functionality to Flash developers. To do this, the entire language has been restructured and new standards have been put in place. ActionScript 2.0 enables the development of more reusable, maintainable , and scaleable applications that appeal to both large and small development teams because it is now an object-oriented language.
Improvements in ActionScript
The ActionScript 2.0 constructs in the following list have been taken directly from the ECMAScript 4 proposal at www.mozilla.org/js/language/es4/:
The ActionScript 2.0 language is much easier to learn for anyone who has had experience with an object-oriented language, and many of the frustrations encountered with ActionScript 1.0 are no longer an issue.
The ActionScript editor itself has also been greatly improved. Normal mode has been eliminated and word wrap has finally been implemented in the editor. Scripts can now be imported as well as exported from the Actions panel. In the Professional edition, it is possible to edit ActionScript files (files with the extension .AS) directly, without seeing the timeline or any other tools.
Before and After in ActionScript
Much of the syntax in ActionScript 1.0 is strange and clunky even to experienced application developers. The language is loosely typed and does not provide an adequate level of error handling. As an example of the difficulty in learning ActionScript for a server-side person, imagine that a Java or C# developer was tasked with learning ActionScript 1.0 to add a front end to a server-side application. For most people familiar with the syntax of an object-oriented language, the weird prototype chaining of ActionScript 1.0 would seem strange and intimidating.
The process of creating classes in ActionScript 1.0 is an odd and convoluted process for those unfamiliar with ActionScript; it bears little resemblance to any other object-oriented language. Finally, the error handling inherent in ActionScript 1.0 is enough to make someone pull out their hair in frustration! Simply spelling a method name or property incorrectly can result in huge frustrations because Macromedia Flash MX 2004 does not always tell the developer about these errors. It just sits there and does nothing!
The new standards of coding in ActionScript 2.0 remedy these problems and enable the user to specify a datatype when declaring variables , use a standard class construct when defining classes, and enable simple and intuitive organization of the application through packages. Best of all, it generates accurate and detailed compile-time errors, as seen in Figure 1.1.
Figure 1.1. Flash now has an error-handling system to make the lives of developers much easier.
Using ActionScript 2.0 to Publish Flash Player 6 Applications
Although the language itself has been entirely restructured to follow uniform coding standards, it is possible to use ActionScript 2.0 to develop for Flash Player 6. The new functionality in ActionScript 2.0 runs on Flash Player 6 because the ActionScript 2.0 code is ultimately compiled to ActionScript 1.0 code. Figure 1.2 shows the interface, which can be used to publish ActionScript 2.0 movies for Flash Player 6. More information on publishing for Flash Player 6 is available in the product help files.
Figure 1.2. You can still target Flash Player 6 even when writing code in ActionScript 2.0.
Behind the scenes, the new ActionScript 2.0 class construct is actually a formalization of the dreaded prototype chain; of course, all the prototyping is completely hidden from ActionScript 2.0 developers. The main disadvantage of the old prototyping was that it was difficult for developers to learn because it did not follow object-oriented standards. To add methods or to create inheritance, you had to use the prototype property of the class. Ultimately, ActionScript 2.0 is still compiled to ActionScript 1.0; however, it is now hidden and it follows standards.
An added benefit of restructuring the language is that Flash can extract more information about its own code and render practices such as using suffixes for objects (remember using _mc for the MovieClip object?) unnecessary. This is true because every object must be declared using variable typing. Even movie clips, components , and text fields can be formally declared in ActionScript 2.0 to take advantage of code hinting.
Whether you use ActionScript 1.0 or ActionScript 2.0, the performance of ActionScript is now blazingly fast. The compiler in Flash now performs enhanced optimizations to all ActionScript code that is compiled. These compiler optimizations greatly enhance the byte code that is generated from ActionScript. Variable-lookup function calls have all been greatly optimized. This results in impressive performance boosts for all ActionScript code, even if you are still writing your applications using ActionScript 1.0. In fact, just by republishing existing applications in Flash MX 2004 (even those that still use Flash Player 6), you can realize significant performance gains. The new ActionScript compiler alone justifies the upgrade to Flash MX 2004!
|< Day Day Up >|