AS2 OOP: Changes and Additions
         by senocular  

ActionScript Compiler
What makes all these new features/behaviors possible, this including the introduction of ActionScript 2.0, is Flash's new robust compiler. A compiler is a program that changes human written code into a program or a file which is more computer friendly or made of "computer code". In Flash's case, it takes your ActionScript and your Flash movie and converts them into swf-worthy byte code.

[ actionscripts and flash movie compiled into swf ]

For a compiler to properly work, however, it also needs to be a good error checker. It needs to recognize when you've screwed up in your coding so it can properly create a working .swf file. Many of the new features in Flash MX 2004, like strict data typing, help this error checking process. They help you make code that helps the compiler let you know when you've done something wrong.

This new compiler, with the introduction of ActionScript 2.0, is also handling the process of converting the code written in the new syntax into proper ActionScript 1.0 code for the .swf file. Because it's doing that conversion, you'll have to realize sometimes that some of these new features won't necessarily be there when playing your Flash movie. Many are just a part of how the compiler interprets your code before converting to ActionScript 1.0 and making a playable movie. You may want to familiarize yourself with the limitations of scripting in ActionScript 1.0 when playing a movie to help you better understand the limitations of ActionScript 2.0 when playing a movie since they still apply.

Strict Data Typing is a good example of this. Data typing your variables does two things: code hints (don't effect a running movie) and checking type compatibility between a variable and a possible value its being assigned. This checking is handled completely by the compiler. Since the compiler is not running when playing a .swf, its possible that, if not caught by the compiler when your movie is published, a certain value of one type can be assigned to a variable of a different type without error. Here's one way to do just that and not have the compiler error.

var value:Number = 1;
trace(value); // 1
 
var tricker = "value";
this[tricker] = "one"; // no error
trace(value); // one

Using associative array syntax with a variable, the compiler is unable assume it knows what the value of tricker will be. As a variable, it could actually be anything at anytime, so there's never a guarantee that it will be a reference to value and therefore the compiler can't call an error because it doesn't can't rightly associate that assignment with any particular value type.

The same applies to most every other new ActionScript 2.0 feature. Chances are that there can be ways which bypass the compiler and slip through to a final swf without being caught. Though Flash MX 2004's new compiler has greatly improved and helps even more in its aide to create correct, well designed applications, it is not perfect and you may have to account for that.

Still, ActionScript 2.0 does hold some wonderful new advancements in defining OO classes. Its about time they get addressed.

 

 

 




SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple.