1.1 ActionScript 2.0 Features

 <  Day Day Up  >  

Introduced in Flash MX 2004 and Flash MX Professional 2004, ActionScript 2.0 is a major grammatical overhaul of ActionScript as it existed in Flash 5 and Flash MX (retroactively dubbed ActionScript 1.0 ). ActionScript 2.0 adds relatively little new runtime functionality to the language but radically improves object-oriented development in Flash by formalizing objected-oriented programming (OOP) syntax and methodology.

While ActionScript 1.0 could be used in an object-oriented way, it lacked a traditional, official vocabulary for creating classes and objects. ActionScript 2.0 adds syntactic support for traditional object-oriented features. For example, ActionScript 2.0 provides a class keyword for creating classes and an extends keyword for establishing inheritance. Those keywords were absent from ActionScript 1.0 (though it was still possible to create prototypical objects that could be used as classes). The traditional OOP syntax of ActionScript 2.0 makes the language quite familiar for programmers coming from other OOP languages such as Java and C++.

Most of the new OOP syntax in ActionScript 2.0 is based on the proposed ECMAScript 4 standard. Its specification is posted at http://www.mozilla.org/js/language/es4.


Here are some of the key features introduced in ActionScript 2.0. Don't worry if these features are new to you; the remainder of the book covers them in detail:

  • The class statement, used to create formal classes. The class statement is covered in Chapter 4.

  • The extends keyword, used to establish inheritance. In ActionScript 1.0 inheritance was typically established using the prototype property but could also be established via the _ _proto_ _ property. Inheritance is covered in Chapter 6.

  • The interface statement, used to create Java-style interfaces (i.e., abstract datatypes). Classes provide implementations for interfaces using the implements keyword. ActionScript 1.0 did not support interfaces. Interfaces are covered in Chapter 8.

  • The official file extension for class files is .as . Formerly, classes could be defined in timeline code or in external .as files. ActionScript 2.0 now requires classes to be defined in external class files. Class files can be edited in Flash MX Professional 2004's script editor or in an external text editor.

  • Formal method-definition syntax, used to create instance methods and class methods in a class body. In ActionScript 1.0, methods were added to a class via the class constructor's prototype property. See Chapter 4.

  • Formal getter and setter method syntax, which replaces ActionScript 1.0's Object.addProperty() method. See Chapter 4.

  • Formal property-definition syntax, used to create instance properties and class properties in a class body. In ActionScript 1.0, instance properties could be added in several ways ”via the class constructor's prototype property, in the constructor function, or on each object directly. Furthermore, in ActionScript 1.0, class properties were defined directly on the class constructor function. See Chapter 4.

  • The private and public keywords, used to prevent certain methods and properties from being accessed outside of a class.

  • Static typing for variables , properties, parameters, and return values, used to declare the datatype for each item. This eliminates careless errors caused by using the wrong kind of data in the wrong situation. See Chapter 3 for details on type mismatch errors.

  • Type casting, used to tell the compiler to treat an object as though it were an instance of another datatype, as is sometimes required when using static typing. See Chapter 3 for details on casting.

  • Classpaths, used to define the location of one or more central class repositories. This allows classes to be reused across projects and helps make source files easy to manage. See Chapter 9.

  • Exception handling ”including the throw and try/catch / finally statements ”used to generate and respond to program errors. See Chapter 10.

  • Easy linking between movie clip symbols and ActionScript 2.0 classes via the symbol Linkage properties. This makes MovieClip inheritance easier to implement than in ActionScript 1.0, which required the use of #initclip and Object.registerClass( ) . See Chapter 13.

 <  Day Day Up  >  


Essential ActionScript 2.0
Essential ActionScript 2.0
ISBN: 0596006527
EAN: 2147483647
Year: 2004
Pages: 177
Authors: Colin Moock

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