User Guide

148 Object-Oriented Programming in ActionScript
ActionScript 3.0 also provides compiler options for each set of properties so that you can
apply the AS3 namespace to your entire program. The
-as3 compiler option represents the
AS3 namespace, and the
-es compiler option represents the prototype inheritance option (es
stands for ECMAScript). To open the AS3 namespace for your entire program, set the
-as3
compiler option to
true, and the -es compiler option to false. To use the prototype
versions, set the compiler options to the opposite values. The default compiler settings for
Adobe Flex Builder 2 and Adobe Flash CS3 Professional are
-as3 = true and -es = false.
If you plan to extend any of the core classes and override any methods, you should understand
how the AS3 namespace can affect how you must declare an overridden method. If you are
using the AS3 namespace, any method override of a core class method must also use the AS3
namespace, along with the
override attribute. If you are not using the AS3 namespace and
want to redefine a core class method in a subclass, you should not use the AS3 namespace or
the
override keyword.
Example: GeometricShapes
The GeometricShapes example application shows how a number of object-oriented concepts
and features can be applied using ActionScript 3.0, including:
Defining classes
Extending classes
Polymorphism and the override keyword
Defining, extending and implementing interfaces
It also includes a “factory method” that creates class instances, showing how to declare a
return value as an instance of an interface, and use that returned object in a generic way.
The GeometricShapes application files can be found in the folder Examples/
GeometricShapes. The application consists of the following files:
File Description
GeometricShapes.mxml The main application file in MXML for Flex.
com/example/programmingas3/
geometricshapes/IGeometricShape.as
The base interface defining methods to be
implemented by all GeometricShapes
application classes.
com/example/programmingas3/
geometricshapes/IPolygon.as
An interface defining methods to be
implemented by GeometricShapes application
classes that have multiple sides.