ActionScript 3 Language Specification
ActionScript 3 Language Specification
0 Language Specification
This document defines the ActionScript 3.0 language, which is designed to be forward-
compatible with the next edition of ECMAScript (ECMA-262).
This document is complete in the syntax and high-level semantics of the language, but
lacks details regarding features that have not changed from the ECMA-262 edition 3
specification, compatibility with ActionScript 2.0, and low-level semantics of some new
features
Source
http://livedocs.adobe.com/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm
1
1 Tutorial introduction
1 Tutorial introduction
An ActionScript program consists of zero or more package definitions followed by zero
or more directives, which includes non-package definitions and statements. Statements
inside and outside of package definitions are evaluated in order, independent of their
nesting inside a package.
The following sections show various ways to implement simple programs such as the
familiar 'hello, world' program in ActionScript 3.0:
trace("hello, world");
This is a single expression statement that calls a function named trace() with the
argument that is a literal string "hello, world" . An expression statement does
nothing but execute an expression.
1.2 Expressions
1+2 evaluates to 3 .
y..z evaluates to the set of all properties identified by z in the value of y and the
descendants of y . The descendants accessor operator (..) is part of the ActionScript
3.0 implementation of ECMAScript for XML (E4X).
1.3 Statements
Statements are executed in the order that they appear in a block. Some statements
change control flow by abrupt completion, such as break and continue , or by iteration,
such as while and do . An example of a statement follows:
for (var i:int = 0; i < 5; i++) {
trace(i);
}
2
1 Tutorial introduction
1.4 Variables
Variables define properties whose values can change at runtime. They can be defined
with either the var keyword or the const keyword. A variable that is defined with
the var keyword may be assigned by any code that can access it. A variable that is
defined with the const keyword may only be set by its initializer, or its class's instance
constructor if it is an instance variable. An example of variables follows:
var x = 10
const PI = 3.1415
1.5 Functions
1.6 Classes
A class is an object that can be used as a constructor of instances that share the same
type and properties. An example of a class follows:
class Greeter {
var saying = "hello, world"
function hello() {
trace(saying)
}
}
var greeter : Greeter = new Greeter
greeter.hello()
3
1 Tutorial introduction
Class definitions are used to define the fixed properties of a class object. Property
definitions that are marked with the static attribute become properties of the class
object, and those that are not become properties of instances of the class.
Class and instance properties are either methods or slots. A method is defined by a
function definition inside a class definition. A method has a definition (called a method
trait) that is shared among all instances of the same type. Unlike an ordinary function
object, a method is tightly bound to the object it is associated with. Whenever and
however it gets invoked, the meaning of the expressionthis is always the same. In
fact, methods can be extracted from their instance and treated as first class objects
(called bound methods), much like function objects can be. There is one important
difference between a function closure and a bound method. With a bound method,
the this reference is bound into the object so that whenever it is invoked the
original this reference is used. With a function closure, this is generic and refers to
any object the function happens to be associated with when it is invoked.
Slots are defined by variable definitions inside a class definition. An instance variable
has a definition (called a slot trait) that is shared among all instances of the same type,
but a unique location in each object.
1.7 Interfaces
An interface defines a contract between an instance and code that uses that instance.
When a class implements an interface, it guarantees that it will provide the methods
declared in that interface. An implementing method must be declared public , in which
case it will implement all unimplemented interface methods with the same identifier. An
example of an interface follows:
interface Greetings {
function hello()
function goodmorning()
}
1.8 Packages
Client code can import all or parts of a package to access the functionality it provides
without cluttering its global namespace with unneeded names. In the following
4
1 Tutorial introduction
example, the import directive makes the class Greeter visible to the global code that
contains the import directive.
package actors {
public class Greeter {
public function hello() {
trace("hello, world")
}
}
}
import actors.Greeter
var greeter : Greeter = new Greeter
greeter.hello()
1.9 Namespaces
Namespaces are useful for controlling the visibility of a set of properties independent of
the major structure of the program. Packages, classes and interfaces, along with their
implicitly defined access control namespaces, allow authors to control the visibility of
names in parallel with the organization of those packages, classes and interfaces. But it
is sometimes necessary to control the names independent of the lexical structure of a
program. Examples of this include the following:
Making the public interface of a set of classes look different to different client
modules
Evolving a class over time without changing the behavior of existing programs
Use packages to give or gain access to a set of features. Use namespaces to give or
gain access to a particular facet, version, or privilege independent of the structure of a
program. An example that uses namespaces follows:
// ActionScript file: actors/English.as
package actors{
public namespace English =
"http://www.adobe.com/2007/Examples/English";
}
5
1 Tutorial introduction
import actors.*;
var greeter : BilingualGreeter = new BilingualGreeter();
use namespace English; // Make all identifiers in the English namespace
// visible
greeter.hello(); // Invoke the English version
greeter.French::hello(); // Invoke the French version
6
2 Design perspective
2 Design perspective
It is sometimes difficult to understand design decisions without understanding the
perspective of the designers. Here are the major viewpoints that have grounded the
design changes introduced in ActionScript 3.0 and ECMA-262 edition 4.
ECMAScript was originally designed for and used by consumers of host object models.
Because ECMAScript is one of the most widely used programming languages, it is
important that existing ECMAScript-compliant programs continue to work in systems
that are updated to support the new definition of the language.
Therefore, programs written for ECMA-262 edition 3, compact profile, or ECMAScript for
XML (ECMA-357 edition 2, also known as E4X) must continue to behave the same way
in both ActionScript 3.0 and ECMA-262 edition 4.
Through 10 years of use, ECMAScript has come under great pressure to become a
language for creating object models. This is a natural consequence of the need for
application and tool developers to extend and override the functionality of the built-in
objects provided by host environments. A few examples of this include HTML, Flash,
Acrobat, and VoiceXML.
These embeddings contain host objects with behaviors that can only be approximated
with the features of ECMA-262 edition 3, and as such are implemented in a way that is
inefficient and fragile.
7
2 Design perspective
Whereas the original purpose of ECMAScript was to provide a scripting language for
automating web pages and other hosted applications where lenient runtime behavior is
preferred and scripts are small enough that performance is often not a concern,
libraries written in ECMAScript can be very large and complex, and be constrained by
aggressive performance requirements. These libraries are often created ahead of time
using IDEs and stand-alone compilers. In this case, developers are willing to give up
some flexibility to be guaranteed that certain kinds of errors will not occur at runtime,
and that their code will run as efficiently as possible.
Therefore, edition 4 allows developers to trade flexibility and compatibility for reliability
and efficiency by choosing a well-defined subset of ECMAScript that can be compiled
ahead-of-time for more aggressive compile-time semantic analysis and optimization.
8
3 Phases and dialects of interpretation
There are two dialects of the language described by this specification, one a subset of
the other. These languages differ only in that one has additional verification rules. The
more permissive language is called the standard dialect, and the more restrictive
language is called the strict dialect.
3.1 Parsing
The parsing phase translates the source code of a program into an internal format
suitable for verification. The syntax rules of the language are described using grammar
productions throughout this specification.
3.2 Verifying
The verification phase ensures that the program obeys the static semantics of the
language. In the standard dialect, verification may be done anytime before a construct
is first evaluated. In the strict dialect, verification must happen before any part of the
program is evaluated.
The differences in the verification rules of the standard dialect and the strict dialect
mean that some programs that would verify in the standard language will not verify in
the strict language. However, all programs that verify in the strict language will verify
and run with the same behavior in the standard language.
Type annotations
Attributes
9
3 Phases and dialects of interpretation
Of these, inheritance clause references and attributes must not have forward
references.
3.3 Evaluating
The evaluation phase takes the parsed, verified program and evaluates it to produce
side effects in its host environment and a final value. The semantics of evaluation are
the same for both dialects of the language.
The goal of strict mode is reliability of new programs. The strict language is a subset of
the standard language and has three kinds of constraints:
Expressions have static types and type errors are verification errors
Here is an example of a program that is valid in the standard dialect but not valid in the
strict dialect:
class A {}
class B extends A {}
var a : A = new B
var b : B = a // type error, static type of 'a' is A,
// which is incompatible with B
In the standard dialect this program has no error, since type errors are runtime errors
and the runtime value of a is an instance of B , which is clearly a member of the type B.
The strict dialect adds various semantic errors to catch common programming mistakes
that are allowed in the standard dialect for the sake of compatibility and flexibility.
Unbound references
10
3 Phases and dialects of interpretation
Unfound packages
11
4 Definitions
4 Definitions
This section defines terms used elsewhere in this specification.
A bound method is a method that is extracted from the instance to which it is attached.
This typically occurs when a method is passed as an argument to a function. Such a
method is bound to the original instance in that the this reference continues to refer to
that instance.
4.2 Class
Every class definition is represented by a special class object that stores information
about the class. Among the constituents of the class object are two traits objects and a
prototype object. One traits object stores information about the static properties of the
class. The other traits object stores information about the instance properties of the
class and serves as the primary mechanism for class inheritance. The prototype object
is a special object that can be used to share state among all instances of a class.
A class method, also called a static method, is a method that is attached to an entire
class, rather than to an instance of a class. Class methods, unlike instance methods,
can only be accessed through the class, and cannot be accessed through a class
instance.
A class variable, also called a static variable, is a variable that is attached to a class
object rather than to an instance of the class. Class variables, unlike instance variables,
can only be accessed through the class, and cannot be accessed through a class
instance.
4.5 Delegate
Delegates are objects that can substitute for other objects during property name
lookup. Every object has a delegate, which is either of the same type as that object or
of type Object. An instance of a class is an example of an object that has a delegate of
the same type. Class instances all share the same delegate--the defining class's
prototype object. A class's prototype object is a special instance of that class that
provides a mechanism for sharing state across all instances of a class.
At runtime, when a property is not found on a class instance, the delegate, which is the
class prototype object, is checked for that property. If the prototype object does not
contain the property, the process continues with the prototype object's delegate. A
prototype object is an example of an object that has a delegate of type Object. All class
12
4 Definitions
prototype objects share the same delegate--a special static property of the Object class
named Object.prototype.
4.6 Final
4.7 Function
A function closure is a function that is neither attached to another object nor defined as
part of a class. Function closures are first-class objects that can be treated as a
collection of properties or as callable objects. Contrast function closures with methods,
which are functions that are attached to an object or an instance of a class.
4.9 Instance
4.12 Method
4.13 Object
13
4 Definitions
4.14 Property
A property associates a name with a value or method. A method can be either a get or
set accessor or an ordinary method. Fixed properties cannot be redefined or deleted.
Dynamic properties are created at runtime and can be redefined and deleted.
Internally, fixed properties are expressed as traits. Dynamic properties are expressed
as a map between names and values.
4.15 Prototype
A prototype object is a special class instance that is stored internally by a class object.
It is an object that becomes the implicit delegate shared by all instances of a particular
class or function. A class prototype is an instance of that class, while the prototype's
delegate is an instance of Object.
4.16 Sealed
4.17 Slots
A slot is a location inside an instance used to store the value of a variable property. A
slot is allocated for each variable declaration.
4.18 Trait
A trait is a fixed property shared by all instances of the same type. The collection of
traits defines the invariants of the object's type. For this reason, use the traits object to
describe the type of an object. Traits are declared in the definition of the class used to
create an object.
class A
{
var x
function m() { }
function get y() { return 10 }
function set y(v) { }
}
Each member of this class definition causes a trait to be added to the traits object for
instances of A. When an instance is created by class A, the resulting object has the
properties x , m , and y , implemented by traits for var x , function m , function get y and
functionset y .
Traits express the type of an instance. All traits are copied down to the derived traits
objects. All traits must be implemented. Interface members are abstract and so their
traits must be implemented in any class that inherits them.
14
5 Names
5 Names
A name consists of a string and a namespace. Names are introduced into a particular
scope by a definition. Those definitions are referred to by names that result from
expressions.
The qualified forms result in a single name consisting of the given qualifier and
identifier. The unqualified forms result in a set of names consisting of strings qualified
by the open namespaces.
The visibility of an identifier is controlled by the set of open namespaces. The set of
open namespaces includes all of the implicitly opened namespaces and the namespaces
opened by the user. The implicitly opened namespaces are as follows:
Public namespace
The namespaces opened by the user are controlled by the use namespace directives
that are in scope. For example:
namespace mx = "http://macromedia.com/mx"
use namespace(mx)
o.m()
In this example, the reference to o.m() will involve the names qualified by the
namespace mx as well as the implicitly opened namespaces: public, internal, etc.
The terms namespace and qualifier are used interchangeably when talking about
qualified names.
A name introduced by a definition might get its qualifier from one of various sources:
Definitions inside a class have the internal namespace of the current package as
their qualifier, unless a namespace attribute is specified
15
5 Names
A definition with an access control attribute has the implicitly defined namespace for
that access specifier as its qualifier
It is an error to introduce a name with an identifier that has already been defined in an
open namespace in the same scope, but with a different qualifier.
Reference names result from various forms of expressions. The two main distinctions in
these forms are whether the name is qualified or unqualified, and whether the identifier
is a literal identifier or an expression.
The following table shows the kinds of references that include qualified and unqualified,
literal and expression names.
Literal Expression
A qualified or unqualified literal identifier is equivalent to the dynamic form with its
expression operand replaced by a string literal representing the literal identifier
A qualified expression reference results in a qualified name that consists of the value
of the qualifier q combined with the string value of the expression expr
Looking up a reference involves determining its ultimate qualified name (in the case of
unqualified references) and its base object.
Object references result from expressions involving the dot or bracket operators. They
may be qualified or unqualified. The following table shows various forms of object
references.
16
5 Names
Literal Expression
We use the expression form of references to describe the name lookup semantics.
However, every literal name can be rewritten as an expression name through the
following steps:
Otherwise, the expression is a qualified literal name, so replace the operand of the
dot operation with the dot operation o.q::['id']
Return m
Let t be the least derived type of x that contains at least one of the names in the
multiname set m of the reference r
Let m' be the intersection of the set of names m and the property names in t
Let n be the set of names in the most derived type of x and in m'
17
5 Names
o.q::[expr]
This is a reference to a property inside the value of o that matches a single name.
Because the qualifier is explicit, the qualified name is straightforward to compute:
Return the qualified name consisting of the namespace ns and the identifier id
q::[expr]
q::id
id
Lexical references result from expressions involving a name but no base object.
Whether a lexical reference is qualified or unqualified, with a literal identifier or
expression, it results in a search of the scope chain of the lexical environment until
either a match is found or the last scope is searched.
Code inside a with statement will have a with frame as the inner most scope on the
scope chain.
Code inside a function definition will have an activation object on its scope chain.
Code inside an instance method will have the instance this object on its scope
chain.
Code inside of a class definition, including in instance and static methods, will have
the class objects of its base classes and the current class on the scope chain. The
inner most class object corresponds to the most derived class, and the outermost
class object corresponds to the Object class.
Code everywhere has the global object as the outer most object on its scope chain.
The base object of a lexical reference is computed through the following steps:
Let n be the qualified name or set of qualified names that result from the operation
described in section 5.3.1.1 Unqualified object references.
Search the scopes in s starting from the innermost scope and continuing outwards
until a scope is found that contains a property that matches n , or all scopes have
been searched.
18
5 Names
If a match is found, return the scope that contains the matching property.
19
6 Types
6 Types
A type is a set of values. Expressions have known values at runtime, and properties
have known types at compile time (as well as at runtime.) The various types of
ActionScript 3.0 can be related graphically as a type lattice where the edges of the
lattice indicate subset relationships.
The following diagram shows the relationships between the main built-in types of the
language:
There are three fundamental program visible types (Null, Object and void). What makes
these types fundamental is that their union includes all possible values in the language.
Null includes null, void includes undefined, and Object includes every other value. Null
and void are different because they do not have object-like properties (such as
toString, valueOf), and they both have values that represent a missing value.
The type Null includes one value - the value that results of the primary
expression null . The value null is used to represent the idea "no value" in the context
of an Object typed reference.
The type void includes one value - the value that is the initial value of the global
property undefined and the result of the unary expression void 0 . The
value undefined is used to represent the idea "no property" or "no value" in the
context of an untyped reference.
While the need for two types that represent the idea of "no value" seems strange to
programmers familiar with statically typed object-oriented languages, the distinction is
useful in ActionScript 3.0 to represent the absence of a property or the absence of a
value of an untyped property versus the absence of a typed property. Here is an
example:
dynamic class A {
var x : String
var y
}
var a : A = new A
print(a.x) // null
print(a.y) // undefined
print(a.z) // undefined
a.y = 10
a.z = 20
print(a.y) // 10
print(a.z) // 20
20
6 Types
When dealing with dynamic instances, there is little difference between a property that
doesn't exist and a property with no type and no value. But there is a difference
between a property that has a type and one that doesn't. This is one of the reasons for
the existence of both types Null and void.
NOTE In ECMA-262 edition 3, program visible values were instances of one of six unrelated types
(Undefined, Null, Boolean, Number, String and Object). Conversions were provided to translate a
value from one type to another. ActionScript 3.0 provides the same conversions between the
primitive types (void/Undefined, Null, Boolean, String, Number, int and uint).
The language includes two type operators that enable programs to test and manipulate
values in terms of a type. These type operators are is and as .
6.1.1 Operator is
The is operator checks to see if the value on the left is a member of the type on the
right. For user-defined types and most built-in types, is returns true if the value is an
instance of a class that is or derives from the type on the right, otherwise it
returns false . For built-in numeric types the result cannot be determined by the class
of the value. The implementation must check the actual value to see if it is included in
the value set of the type.
The following table shows the results of using various values and types with
the is operator:
21
6 Types
6.1.2 Operator as
The purpose of the as operator is to guarantee that a value is of certain type, and, if
not, indicate so by returning the value null .
Throw a TypeError
If v is of type T
Else
22
6 Types
The as operator
Other operators
The result of the conversion depends on the context of the expression that yields the
value to be converted:
Implicit conversion to T
var x : T = v
var y : T = v as T v or null
When the destination type is a user-defined type T , an implicit conversion will succeed if
the value is an instance of a class that is T or is derived from T . If an implicit conversion
does not succeed, then a type error is thrown.
When the destination type is a primitive type, the implicit conversion is described by
the corresponding abstract procedure (such astoString() and toNumber() .) The
following table shows some implicit conversion results:
0 "0" 0 0 0 false 0
1 "1" 1 1 1 true 1
23
6 Types
User-defined types do not have built-in conversion operators, so implicit and explicit
conversions behave the same at runtime. Specifically, if a value is not a member of the
destination type, then no conversion exists, implicit or explicit, and a runtime exception
will result from a cast expression and the default value of the destination type (which
is null ) will be the result of an as expression.
In the standard dialect, type mismatches are not reported at compile time. Rather, a
runtime type conversion is attempted and an error is reported if the type conversion
fails. For example, the following example not only compiles in the standard dialect, but
also does not cause a runtime error:
var num : Number = "1.23"
trace(num is Number) // output: true
In the strict dialect, type mismatches are reported as compile-time errors. Accordingly,
the previous example does not compile in strict mode because the string
value "1.23" is not a member of the Number data type. In other words, a
variable v that uses the following syntax will not compile unless v is a member of data
type T :
var v:T
We sometimes refer to a class or interface that helps to define the structure of a value
as the value's type. What we really mean is that that value is a member of that class or
interface type. This distinction is subtle but important. Since a value might belong to
any number of unrelated types, to say that it is of a particular type is misleading.
In dynamically typed languages, expressions don't have types; they have values whose
types may change each time the expression is evaluated.
Statically typed languages make the important simplification of associating a type with
every expression, even if it is a very general one, when it is compiled. In this way, the
suitability of an expression can be checked against its use before it is ever actually run.
The cost of this added reliability is the loss of flexibility that comes from not having to
think about the types of values.
24
6 Types
function f( o : Object ) {
var x : Number
x = o // Allowed in the standard dialect
}
f(10) // No problem, x gets set to 10
Other places where the differences between dynamic and static type checking can be
seen are property access, and method invocation.
function f( o : Object ) {
o.g()
return o.x
}
Whereas in a static type system, the binding for a method call or property read would
need to be known at compile-time, the standard dialect always defers that checking
until runtime.
The strict dialect has a hybrid type system. Normally, static type rules are used to
check the compatibility of an expression with its destination type, but there are a few
special cases. For example, when an expression on the right-hand side of an
assignment expression consists of a reference to a property with no type, name lookup
is deferred to runtime. When an object reference has a base object that is an instance
of a dynamic class, the reference is checked at runtime. These dynamic typing features
are useful when strict dialect programs are interoperating with dynamic features such
as XML objects.
A property without a type annotation or with the wildcard annotation * (as in var x :
* ) is said to be untyped. Writing to an untyped property will always succeed since an
untyped property can hold any value. Expressions that read from an untyped property
are said to be untyped expressions. Assignment from an untyped expression may or
may not succeed at runtime depending on whether its value can be implicitly converted
to the destination type. Nevertheless, in the strict dialect, assignments from untyped
expressions are always type-checked at runtime, as in the standard dialect.
Use untyped properties when you want to store the result of an untyped expression
or undefined as one of the values, or when you want to defer type checking to
runtime.
All program-visible types other than void and Null derive from type Object. This means
that all values (except undefined and null ) have properties that can be accessed by
object references without the need to be wrapped in an object as they were in ECMA-
262 edition 3.
25
6 Types
class A
{
static var x
var y
prototype var z
}
var a : A // A means type A
a = new A // A means value A
The value is a class object that has the form shown in the drawing above. The class
object is CA. When used as a type, it evaluates to its instance traits (TA). When used in
a new expression, the class serves as a factory object with a special method that
creates a new instance (OA), which contains an internal delegate property pointing to
the class object's prototype (P) and an internal traits property pointing to the class
object's instance traits (TA).
In the strict dialect, both expressions and properties have types. To be used to compute
the value of a property, the expression must have a static type that is compatible with
the type of the property. One way to think about static types of expressions and values
is that the static type is a conservative approximation of the set of values that will
result from that expression.
There are three special cases where static type rules are ignored, possibly allowing
runtime errors to occur:
26
6 Types
An explicit cast to a user-defined type is only useful in the strict dialect. This is because
the effect of an explicit cast is to defer type checking until runtime, which is already the
case in the standard dialect. This is not necessarily the case for built-in types that have
special conversion behavior.
27
7 Variables
7 Variables
A variable defines a slot with a name and a type.
A variable declared with the const rather than the var keyword, is read-only outside of
the variable's intializer if it is not an instance variable and outside of the instance
constructor if it is an instance variable. It is a verifier error to assign to a const variable
outside of its writable region.
Class objects
Instance objects
Activation objects
When allowed by the context of the definition, the following attributes modify a variable
definition.
static
prototype
Access control and visibility control namespaces specify the namespace part of the
variables name.
The static attribute may only be used inside a class definition and causes the variable to
become a trait of the class object rather than the instance object.
The prototype attribute may only be used inside a class definition and causes the
variable to be added to the class's prototype object and a get and set accessor to be
added to the instance traits of the class. The purpose of the accessor methods is to
simulate the behavior of accessing prototype properties in ECMA-262 edition 3.
All variables can have a type. A type annotation on a variable definition limits the set of
values that can be stored in that variable. A type annotation must be a compile-time
constant expression that evaluates to a class or interface value. The actual value used
to represent the type of the variable is the instance traits of the referenced class or
interface.
28
7 Variables
29
8 Functions
8 Functions
A function is a callable object. In general, functions consist of a block of code, a set of
traits, and a list of scopes. Instance methods are functions that also consist of a
receiver object to which this references are bound.
When allowed by the context of the definition, the following attributes modify a function
definition:
static
final
override
native
Access control and visibility control namespaces specify the namespace part of the
function name.
The static attribute may only be used inside a class definition and causes the function
to become a trait of the class object rather than the instance object.
The final attribute may only be used on a non-static function definition inside a class.
A function modified by final cannot be overridden.
The override attribute may only be used on a non-static function definition inside a
class. A function modified by override will override a method with the same name and
signature as a non-final method of a base class.
The native attribute may be used to indicate that the function is implemented in an
implementation-defined way. The compiler should generate native stubs for functions
that have this attribute.
A function signature includes the number and types of its parameters and its result
type. Like variable type annotations, the types of a function signature affect the implicit
conversion of argument and return values when calling to and returning from a
function. Function signatures are also used to match inherited methods to methods in a
derived class.
30
8 Functions
Function objects have a property named prototype whose value is used to initialize the
intrinsic delegate property of the objects it creates. The prototype property has a
default value of a new instance of the class Object. Building on the previous example:
function A() { this.x = 10 }
function B() {}
B.prototype = new A
var o = new B
trace(o.x) // traces 10
Constructor methods inside of a class are also used to create objects. But, unlike
constructor functions, constructor methods create objects with a set of fixed properties
(traits) associated with its class and a delegate that is also an instance of its class.
class A {
var x
function A() { this.x = 10 }
}
var o = new A
trace(o.x) // traces 10
There are some subtle differences between the preceding example and the one
involving a function constructor:
The expression A(expr) does not call the function A defined in class A . It results in
an explicit conversion of the value of expr to the type A .
Class methods are functions that are defined with the static attribute inside of a class
definition. A class method cannot be used as a constructor and does not define
the this reference. Class methods are in the scope of the class object in which they are
defined.
Instance methods are functions that are defined without the static attribute and inside
a class definition. Instance methods are associated with an instance of the class in
which they are defined. Instance methods can override or implement inherited class or
interface methods and always have a value bound to this .
The value of this in an instance method is the value of the instance the method
belongs to. When an instance method is extracted from an object, a bound method is
31
8 Functions
created to bind the value of this to that host object. Assignment of the bound method
to a property of another object does not affect the binding of this . For example:
class A {
var x
function A() { this.x = 10 }
function m() { trace(this.x) }
}
var a = new A()
var o = { x : 20 }
o.m = a.m
o.m() // traces 10
32
9 Classes
9 Classes
A class is a type, a constructor of objects of that type, and a singleton object for
sharing state and behavior. It is used as a constructor to create like instances. It is
used as a type to constrain the value of properties. It is used as a singleton object to
contain shared properties.
Classes are introduced with class definitions. A class definition can directly extend one
other class definition and implement multiple interface definitions. The language does
not support the concept of abstract classes and so a class must implement every
interface method it inherits.
The default modifiers for a class definition are internal, non-dynamic, and non-final.
Class objects have the basic structure shown in the following illustration:
The illustration shows the shape of the class object that results from the following
simple class definition:
33
9 Classes
9.2.1 Prototypes
Every object has a prototype object that is used to match references at runtime. This
prototype is called the delegate of the object. Delegation is a simple way to add shared
properties to a group of related objects at runtime.
Prototype objects are always instances of the dynamic class Object and therefore can
always be extended by the addition of dynamic properties. Unlike with function closures
that have a prototype property that is a variable and can be reset to another object,
classes have a prototype that is read-only and so always point to the same object.
9.2.2 Traits
Properties of a class definition are represented as traits of the class object and its
instances. Think of a trait as a fixed property that is shared by all instances of a type.
Class objects (CA) are special in that they are a single instance with an internal type
with a corresponding set of traits (TCA). The internal type of a class object describes
the static properties of the class definition. The instance traits (TA) are shared by all
instances created by the class object. They correspond to the instance properties of the
class definition.
class A
{
static var x
var y
}
In this example, the definition for x contributes a trait to the class traits (TCA), and the
definition of y contributes a trait to the instance traits (TA).
9.2.3 Methods
Each function definition inside a class definition results in a method inside the resulting
class object or its instances. Two special methods are implicitly defined for each class: a
class initializer; and an instance initializer. Code outside a function definition gets
placed in the class initializer, which is called when the class object is created. Instance
variable initializers are placed in the instance initializer method, which is called when an
instance of the class is created and before the user-defined constructor is executed.
9.2.4 Slots
Traits introduced by variable definitions describe a property that holds a value unique to
each instance. Therefore, each object has a fixed array of slots that store those values,
one for each variable trait. This is true of class objects as well as instance objects.
34
9 Classes
9.2.5 Instances
All instances (OA) created by a class object (CA) will be given a traits (TA) and delegate
(PA) object, as represented in this drawing
9.2.6 Inheritance
Each class inherits the instance traits of its base class. These traits are effectively
copied down to the instance traits of the derived class. Classes that don't declare an
explicit base class inherit the built-in Object class.
A class may also inherit the instance traits of one or more interfaces. Interface traits
are abstract and so must be implemented by any class that inherits them.
9.2.7 Scopes
Static properties are in scope of bodies of static and instance methods of the same
class. Instance properties are in scope of the bodies of the instance methods. Instance
properties shadow static properties with the same name. Static properties of base
classes are in scope of static and instance methods of a class.
class A
{
static var ax
}
class B extends A
{
static var bx
}
class C extends B
35
9 Classes
{
static var cx
var ix
function m()
{
var mx
gx = 10
ax = 20
bx = 30
cx = 40
mx = 50
}
}
var gx
o = new C
o.m()
Scopes:
{ mx } - activation scope
{ ix } - instance scope
{ cx } - static scope C
{ bx } - static scope B
{ ax } - static scope A
{ gx } - global scope
protected Visible to references inside instances of the current class and derived classes
AttributeExpression Namespace value is the qualifier for the name of the definition
It is a syntax error to use any other attribute on a class property, unless otherwise
specified in the section describing the specific type of property.
The static attribute means the current definition defines a property of the class object.
36
9 Classes
Each access control attribute (private , internal , protected , and public ) refers to a
namespace value with a unique, private namespace name. Access control is provided
by the fact that code outside of the attribute's access domain has no way to refer to
that namespace value.
Definitions result in class or instance traits depending on whether the static attribute
occurs in their definition.
Statements and initializers of static variables are added to the static initializer
method of the class. The static initializer is called once, when the class is defined at
runtime. The static initializer can be used to initialize variables of the class object
and to invoke methods that are external to the current class.
37
9 Classes
The scope chain of methods contained by the class body includes the class object,
the base class objects (from most derived the least derived), and the global object.
Note that it is not an error to define a class and instance property with the same name,
as in the following example:
class A {
static var x
var x
}
It is also not an error to define a class property with the same name as a visible class
property in a base class:
class A {
static var x
}
class B extends A {
static var x
}
The meaning of var and const follow from the general meaning described in the
sections 7 Variables and 1.4 Variables.
const variable properties can be written to only once. The compiler uses a specific data
flow analysis to determine if a const variable has been written to at the point of an
assignment to that variable. Informally, the effect of this algorithm can be seen in the
following error cases:
It is an error to assign to a const variable in more than one parallel control flow
branch if the branch conditions are not compile-time constant expressions, or if the
38
9 Classes
value of those branch conditions allow for one or more of those branches to be
executed more than once.
The default value of a class or instance variable is the value of undefined coerced to the
type of the variable.
Variables declared with the static attribute add a slot trait to the class traits and a slot
to the class object. Because there is only one class object per class, there is also only
one slot per static variable. Static variables, like static methods, are not inherited, but
are accessible from within the body of the class definition and through an explicit
reference to the defining class's name. Static variables are in scope for all static and
instance methods of the defining class and classes that inherit the defining class.
Static const variables must either have an initializer or be definitely unassigned before
being set in the static initializer method.
NOTE Unlike in Java and C#, static variables are not inherited by derived classes and so cannot be
referenced through derived class objects.
Variables declared without the static attribute add a slot trait to the instance traits of
the class and a slot to each instance of the class. Instance variables are always final
and must not be overridden or hidden by a derived class.
As with all class properties, the default qualifier for the variable is the internal
namespace. Other qualifiers can be specified by other namespace attributes. Both
instance and class variables are implicitly final. Any attempt to hide or override one in a
derived class will result in a verification error.
A function declared with the same identifier as the class it is defined in adds a
constructor method to the class object. The constructor is called when a new instance
of that class is created. A constructor may refer to the instance variables of the class
that defines it.
39
9 Classes
class A
{
function A() {}
}
A constructor is public by default and may be defined with the public namespace or with
no namespace attribute. If no constructor is defined by a class definition, a default
constructor is defined implicitly. No more than one constructor can be defined for a
class.
NOTE That there is no way to directly call the constructor of an indirect base class is intentional because it
might lead to brittle or insecure programs.
Functions declared with the static attribute add a method trait to the class object
traits. Static variables are in scope of a static method.
It is an error for the this or super expression to appear in the body of a static method.
NOTE Unlike in Java and C#, static variables are not inherited by derived classes and so cannot be
referenced through derived class objects.
Functions declared without the static attribute add a method trait to the instance
traits of a class object. Static and instance variables are in scope of an instance
method. The value of this inside an instance method is the instance the method is
bound to.
class A
{
function m() { return this }
}
var a = new A
trace(a==a.m()) // trace true, this is the object 'm' is called on
In addition to the attributes defined for all class properties, the following attributes may
be used on instance methods
40
9 Classes
The override attribute helps to avoid unintentional overriding of base class methods. It
is a verifier error to use the override attribute on a function definition that does not
override an inherited method. It is a verifier error to override an inherited method that
is declared final. It is an error to define a method without the override attribute if the
name matches the name of an inherited method.
The prototype attribute allows the addition of a fixed property to the prototype object,
but not to the instance. Instance methods defined with the prototype attribute have
function values that are compatible with ECMA-262 edition 3 prototype functions.
class A
{
prototype var f = function() { return this }
}
var a = new A
dynamic class B {}
var b = new B
b.f = a.f
b.f() // traces "[object B]"
A method defined with the get or set keyword adds a get or set method trait to the
instance or static traits of the defining class object. Accessor methods are called when
the name of the accessor is used in a reference that reads or writes the value of that
name.
class A
{
private var _x
function get x() { return _x }
function set x(v) { _x = v }
}
var a = new A
a.x = 10 // calls set accessor of A
trace(a.x) // traces 10, calls get accessor of A
Accessor methods are very similar in definition to regular methods. The differences are
expressed by the following error conditions:
41
9 Classes
Set methods must not specify a result type other than void .
If both a get and set method is defined with the same name, the parameter type of
the set method and the result type of the get method must match.
NOTE Accessors may only be defined at the top level of a class. They must not be nested inside another
method or defined outside of a class.
Instance methods are inherited by copying their instance traits down to the instance
traits of the derived class.
Methods inherited from a class may be overridden in the derived class if the overriding
method is given the override attribute and if its name, number and type of parameters,
and return type match exactly. It is an error to attempt to override a method with a
method that has the same name, but does not have the same number of parameters or
parameters of different types or different return type.
A method that has the public attribute implements all inherited interface methods with
a matching identifier.
interface I
{
function m()
}
interface J
{
function m()
}
42
9 Classes
Although a method is not a value by itself, it can be converted to a first class value
called a bound method, through extraction. A bound method maintains the binding
between a method and its instance. The user-visible type of a bound method is
Function.
class A
{
function m() { return this }
}
var a = new A
var mc : Function = a.m // create a bound method from m and a
trace(a==mc()) // trace true, mc remembers its this
43
10 Interfaces
10 Interfaces
Interfaces provide a way for programs to express contracts between the producers and
consumers of objects. These contracts are type safe, easy to understand, and efficient
to implement. Programs should not have to pay a significant performance penalty for
using interfaces.
An interface is a type whose methods must be defined by every class that claims to
implement it. Multiple interfaces can be inherited by another interface through
the extends clause or by a class through the implements clause. Instances of a class
that implements an interface belong to the type represented by the interface. Interface
definitions must only contain function definitions, which may include get and set
methods.
Interface methods are not public by default, but are added to the public namespace by
the implementing method definition.
An interface definition introduces a type into the current scope. The interface type is
described by a set of abstract method traits and a list of interfaces that it extends. This
set of abstract traits must be fully implemented by any class that inherits the interface.
An interface name refers to the interface type when it is used in a type annotation or an
inheritance clause of a class or interface definition.
interface I {}
class A implements I {} // I refers to type I
var x : I = new A // In each of these uses too
trace( x is I )
var y : I = x as I
In this example, T in the is expression refers to the outer interface T , not the inner
var T .
44
10 Interfaces
Classes that implement an interface method must use the public attribute to
implement all interface methods that have the same identifier name. The following
example shows a class that implements two inherited interfaces with public qualified
methods.
interface I
{
function f()
}
interface J
{
function g()
}
class A implements I
{
public function f() {}
public function g() {}
}
Interface methods are visible when referenced through a property of the corresponding
interface type or through a reference to the implementing class or subclass.
var a : A = new A
a.f() // okay, f is visible through an A as {public}::f
a.g() // okay, g is visible through an A as {public}::g
var i : I = b
i.f() // okay, f is still visible through an I as {I}::f
i.g() // error, g is not visible through an I as {I}::g
References through an object with an interface type are multinames that contain only
the names qualified by the interface namespace and its super interface namespaces.
This means that the names in the open namespaces (including public) will not be visible
through a reference with an interface-typed base object. The motivation for this
behavior is to express the idea of the interface as a contract between the producer and
consumer of an object, with the contract specified by the names in the interface
namespace alone.
If the compile-time type of the base object is not an interface type, an unqualified
reference will use the currently open namespaces (which includes public) to create a
multiname in the normal way. Again, ambiguous references can be explicitly qualified
with the interface name to avoid conflicts.
The rules for implementing an inherited interface method are the same as the rules for
overriding an inherited class method. Specifically, the name of the method, number and
type of the parameters, and return type must match exactly.
45
10 Interfaces
The following example shows how interfaces are defined and used.
interface T
{
function f()
}
interface U
{
function f()
function g()
}
class A implements V
{
public function f() {} // implements {T,U}::f
public function g() {} // implements {U}::g
public function h() {} // implements {V}::h
}
var a : A = new A
var t : T = a
var u : U = a
var v : V = a
var o = a
The static type of the base object of a reference controls which interface names are
open in that reference if that type is an interface type.
46
11 Packages
11 Packages
A package definition introduces a top-level namespace, suitable for organizing
collections of type definitions into APIs.
.
.
.
}
The semantics of loading packages is outside of the language definition. The compiler
and virtual machine will have access to the package definitions in files that have been
loaded by the embedding tool or runtime.
The namespace name (the string used for equality comparision) of a package is the
sequence of characters of its name. For example, the package in:
package mx.core {
.
.
.
}
47
11 Packages
package acme.core
{
public class Widget { } // qualifies Widget
}
Packages exist only at compile time. The static existence of packages allows us to give
them certain properties that would not be possible if they could be manipulated at
runtime. In particular:
Fully qualified package references may and must be expressed using the dot
operator rather than the usual :: syntax for qualified names
But because there is no runtime value for a package name, packages cannot be aliased
or otherwise used in an expression that uses a runtime value.
When encountered in a valid context by the compiler, the meaning of a package name
becomes fixed; any interpretation at runtime is no longer possible.
For this reason, a package name always shadows locally defined names, independent of
the scope chain, when that package name is used on the left hand side of a dot
operator.
package p
{
public var x = 10
}
import p.x
function f()
{
var p = { x : 20 }
trace(p.x) // traces 10
}
f()
Definitions with the public attribute inside a package definition are implicitly qualified
by the package namespace. Every kind of definition except for package definitions may
appear directly inside a package definition, including variable, function, namespace,
class, and interface definitions.
48
11 Packages
The visibility of a name defined inside of a package is controlled by the attributes that
appear in that definition. Allowed attributes include the following:
internal Qualified by the internal namespace for the current package [default]
It is a syntax error for more than one of these attributes to appear in a definition.
The names of package members are made visible inside an external scope with
an import directive. For example, the following code makes all public names defined in
the package mx.core visible inside any scope that contains this directive:
import mx.core.*
Individual names can be imported using an import directive with the fully qualified
name to be imported. For example, the following code has the effect of making the
class mx.core.Image, but no other names defined inside package mx.core, visible to an
unqualified reference.
import mx.core.Image
References to package members are fully qualified using the dot operator. When the
meaning of a simple name is ambiguous, a fully qualified name can be used to indicate
the intended binding. For example:
import mx.core.*
import player.core.*
import acme.core.*
new WidgetImpl // error, cannot find WidgetImpl
new Widget // okay, public names are always visible
49
11 Packages
A name alias can be provided for single name import directives to avoid ambiguity of
unqualified references, as shown in the following code:
package acme.core
{
public class Widget { }
}
package mx.core
{
public class Widget { }
}
When an alias is specified, the original fully qualified name can be used to refer to the
imported definition. It is also possible to use the original unqualified name as long as
the resulting reference is not ambiguous.
The unnamed package is implicitly imported by all other packages and global code
outside of any package. This makes it convenient for casual sharing of definitions
between programs by making public definitions in the unnamed package always visible.
50
12 Namespaces
12 Namespaces
Namespaces are used to qualify names. ECMAScript for XML (E4X) introduced the idea
of explicitly qualifying names to reference properties of an XML object. XML
namespaces allow markup with various meanings, but potentially conflicting names, to
be intermixed in a single use. Packages in ActionScript 3.0 provide such a capability.
XML namespaces also allow names to be individually qualified to create sub-
vocabularies relating to concerns secondary to the main purpose of the markup.
Namespaces in ActionScript 3.0 provide this capability, that is, controlling the visibility
of names independent of the structure of the program. This is useful for giving trusted
code special access privileges and for distinguishing the meaning of a name between
versions and uses.
Namespace definitions introduce a constant fixed property of type Namespace into the
defining scope. The property is initialized to an implicit or explicit value. Regardless of
how it is initialized, a namespace value consists of a namespace name used for equality
comparison.
The set of attributes that may be used on a namespace definition is the same as the set
that can be used on a variable definition.
Here, two distinct variables are defined--one with the qualified name N1::x and the
other with the qualified name N2::x . Referencing code can refer to one or the other of
these names by explicitly qualifying references to x or by adding one or the other
namespace to the set of open namespaces.
51
12 Namespaces
trace(N1::x)
The set of open namespaces determines the visibility of unqualified references. If the
qualifier of a name is not in the set of open namespaces, it will not be visible to an
unqualified reference. Namespaces are added to the list of open namespaces by the use
namespace directive. Building on the previous example, the namespace N1 is added to
the set of open namespaces:
namespace N1
namespace N2
N1 var x : int = 10
N2 var x : String = "hello"
use namespace N1
trace(x) // trace 10
The unqualified reference to x matches any name that has the identifier x and is
qualified by one of the open namespaces, in this caseN1::x .
It is a runtime error for more than one name to match an unqualified reference.
The set of open namespaces includes any namespace that is explicitly used in that
block or an outer nested block, as well as the public, internal, protected, and private
namespaces that are implicitly open in various contexts.
Bindings of explicitly used namespaces are preferred over names in the public
namespace. This allows a public name to be given an open user-defined namespace
without making unqualified references ambiguous:
namespace N1
N1 var x : int = 10
public var x : String = "hello"
use namespace N1
trace(x) // okay, matches N1::x, even though public::x is also visible
52
12 Namespaces
class A {
private namespace Key
private var friends = [ B ]
function beMyFriend( suitor ) {
for each( friend in friends )
{
if( suitor is friend ) return Key
}
return null
}
Key function makeMyDay()
{
trace("making my day")
}
}
class B {
function befriendAnA(a:A) {
var key : Namespace = a.beMyFriend(this)
if( key != null )
{
a.key::makeMyDay()
}
}
}
package p {
public namespace V2
public class A {
public function m() {}
V2 function m() {}
}
}
import p.v1
import p.v2
import p.A
// version 1
class B extends A
{
public function m() {}
}
// version 2
53
12 Namespaces
class B extends A
{
public function m() {}
V2 function m() {}
}
import p.*
{
use namespace French
use namespace Vegan
person.sayIt() // speak French
person.eatIt() // eat vegan
}
{
person.sayIt() // speak English
person.eatIt() // eat meat
}
54
13 Lexical Structure
13 Lexical Structure
13.1 Lexical
Lexical keywords are removed from the available program namespace during scanning.
It is a syntax error to use any of these names except as indicated by the grammar.
Syntactic keywords appear to the lexical scanner as identifier tokens, but are given
special meaning in certain contexts by the parser.
The following list contains all identifiers that are syntactic keywords:
each get set namespace include dynamic final native override static
13.2 Syntactic
In a for-each-in statement between the 'for' token and the '(' token:
each
In these cases, the grammar requires an identifier after the namespace keyword.
55
14 Expressions
14 Expressions
The syntax in this section contains the following superscript and subscript symbols:
The noIn superscript is attached to nonterminals with definitions that do not include
a production rule that contains the in operator. This superscript is necessary to
avoid conflicts between the in operator as part of a relational expression and
the in operator as part of a for statement.
14.1 Identifiers
Syntax
Identifier
Identifier
dynamic
each
get
include
namespace
set
static
56
14 Expressions
PropertyIdentifier
Identifier
Qualifier
PropertyIdentifier
ReservedNamespace
SimpleQualifiedIdentifier
PropertyIdentifier
Qualifier :: PropertyIdentifier
Qualifier :: Brackets
ExpressionQualifiedIdentifier
ParenExpression :: PropertyIdentifier
ParenExpression :: Brackets
NonAttributeQualifiedIdentifier
SimpleQualifiedIdentifier
ExpressionQualifiedIdentifier
QualifiedIdentifier
@ Brackets
@ NonAttributeQualifiedIdentifier
NonAttributeQualifiedIdentifier
57
14 Expressions
respectively, where the expression between Brackets is a string literal with the same
sequence of characters as the PropertyIdentifier.
Verification
Identifier : Identifier
Identifier : each
Identifier : get
Identifier : include
Identifier : namespace
Identifier : set
PropertyIdentifier : Identifier
Qualifier : PropertyIdentifier
Qualifier : ReservedNamespace
SimpleQualifiedIdentifier : PropertyIdentifier
Return the result of verifying the non-terminal symbol on right-hand side of the
production
Call verifyType(qual,Namespace)
Call verifyType(qual,Namespace)
58
14 Expressions
Call verifyType(qual,Namespace)
Call verifyType(qual,Namespace)
NonAttributeQualifier : SimpleQualifiedIdentifier
NonAttributeQualifier : ExpressionQualifiedIdentifier
Return the result of verifying the non-terminal symbol on right-hand side of the
production
QualifiedIdentifier : @ Brackets
Verify Brackets
QualifiedIdentifier : @ NonAttributeQualifiedIdentifier
QualifiedIdentifier : NonAttributeQualifiedIdentifier
Verify NonAttributeQualifiedIdentiifer
Evaluation
Identifier : Identifier
Identifier : each
Identifier : get
Identifier : include
59
14 Expressions
Identifier : namespace
Identifier : set
Return a new String value consisting of the sequence of characters of the token on
the right-hand side of the production
PropertyIdentifier : Identifier
PropertyIdentifier : *
Qualifier : PropertyIdentifier
Qualifier : ReservedNamespace
SimpleQualifiedIdentifier : PropertyIdentifier
Return the result of evaluating the non-terminal symbol on right-hand side of the
production
Return name
60
14 Expressions
Return name
NonAttributeQualifier : SimpleQualifiedIdentifier
NonAttributeQualifier : ExpressionQualifiedIdentifier
Return the result of evaluating the non-terminal symbol on right-hand side of the
production
QualifiedIdentifier : @ Brackets
QualifiedIdentifier : @ NonAttributeQualifiedIdentifier
QualifiedIdentifier : NonAttributeQualifiedIdentifier
Return name
61
14 Expressions
Syntax
PrimaryExpression
null
true
false
Number
String
this
RegularExpression
QualifiedIdentifier
XMLInitializer
ReservedNamespace
ParenListExpression
ArrayInitialiser
ObjectInitialiser
FunctionExpression
Verifition
PrimaryExpression : null
PrimaryExpression : true
PrimaryExpression : false
PrimaryExpression : Number
62
14 Expressions
PrimaryExpression : String
PrimaryExpression : RegularExpression
PrimaryExpression : QualifiedIdentifier
PrimaryExpression : XMLInitialiser
PrimaryExpression : ReservedNamespace
PrimaryExpression : ParenListExpression
PrimaryExpression : ArrayInitialiser
PrimaryExpression : ObjectInitialiser
PrimaryExpression : FunctionExpression
Return the result of verifying the non-terminal symbol on the right-hand side of the
production
PrimaryExpression : this
If frame is none
Throw a VerifyError
Evaluation
PrimaryExpression : null
PrimaryExpression : true
PrimaryExpression : false
PrimaryExpression : Number
63
14 Expressions
PrimaryExpression : String
PrimaryExpression : this
PrimaryExpression : RegularExpression
Return the RegExp result of evaluating the expression produced by lexical analysis
of RegularExpression
PrimaryExpression : QualifiedIdentifier
Return ref
Syntax
ReservedNamespace
public
private
protected
internal
Verification
ReservedNamespace : public
ReservedNamespace : private
ReservedNamespace : protected
Throw a VerifyError
64
14 Expressions
ReservedNamespace : internal
Throw a VerifyError
Evaluation
ReservedNamespace : public
ReservedNamespace : private
ReservedNamespace : protected
ReservedNamespace : internal
Syntax
ParenExpression
( AssignmentExpressionallowIn )
ParenListExpression
ParenExpression
( ListExpressionallowIn , AssignmentExpressionallowIn )
Verification
ParenExpression : ( AssignmentExpressionallowIn )
65
14 Expressions
Verify ListExpression
Evaluation
ParenExpression : ( AssignmentExpressionallowIn )
Evaluate ListExpression
Let ref be the result of evaluating AssignmentExpression
Return the result of readReference(ref)
Syntax
FunctionExpression
function FunctionCommon
Verification
Evaluation
66
14 Expressions
Add a property to obj with the name id and the value fun that is not writable and
not deletable
Pop obj from the scope chain
Return fun
Syntax
ObjectInitialiser
{ FieldList }
FieldList
«empty»
NonemptyFieldList
NonemptyFieldList
LiteralField
LiteralField , NonemptyFieldList
LiteralField
FieldName : AssignmentExpressionallowIn
FieldName
NonAttributeQualifiedIdentifier
String
Number
Verification
ObjectInitialiser : { FieldList }
67
14 Expressions
FieldList : empty
Do nothing
FieldList : NonemptyFieldList
Verify NonemptyFieldList
NonemptyFieldList : LiteralField
Verify LiteralField
Verify LiteralField
Verify NonemptyFieldList
Verify FieldName
Verify AssignmentExpression
FieldName : NonAttributeQualifiedIdentifier
Verify NonAttributeQualifiedIdentifier
FieldName : String
FieldName : Number
Do nothing
Evaluation
ObjectInitialiser : { FieldList }
FieldList : empty
FieldList : NonemptyFieldList
NonemptyFieldList : LiteralField
68
14 Expressions
Call objectWrite(obj,name,val)
FieldName : NonAttributeQualifiedIdentifier
FieldName : String
FieldName : Number
Array elements may be elided at the beginning, middle or end of the element list.
Whenever a comma in the element list is not preceded by an AssignmentExpression
(such as a comma at the beginning or after another comma), the missing array element
contributes to the length of the Array and increases the index of subsequent elements.
Elided array elements are not defined.
Syntax
ArrayInitialiser
[ ElementList ]
69
14 Expressions
ElementList
«empty»
LiteralElement
, ElementList
LiteralElement , ElementList
LiteralElement
AssignmentExpressionallowIn
Verification
Evaluation
Syntax
XMLInitialiser
XMLMarkup
XMLElement
XMLElement
70
14 Expressions
XMLTagContent
XMLTagName XMLAttributes
XMLTagName
{ Expression }
XMLName
XMLAttributes
XMLWhitespace { Expression }
XMLAttribute XMLAttributes
«empty»
XMLAttribute
XMLElementContent
{ Expression } XMLElementContent
XMLMarkup XMLElementContent
XMLText XMLElementContent
XMLElement XMLElementContent
«empty»
See the ECMAScript for XML (E4X) specification (ECMA-357 edition 2) for definitions of
XMLMarkup, XMLText, XMLName, XMLWhitespace and XMLAttributeValue.
Verification
An XMLInitialiser is verified by verifying all non-terminals on the right hand side of each
production. The result of verifying an XMLInitialiser is the type XML.
Evaluation
71
14 Expressions
SuperExpression limits the binding of a reference to a property of the base class of the
current method. The value of the operand must be an instance of the current class. If
Arguments is specified, its value is used as the base object of the limited reference. If
no Arguments is specified, the value of this is used as the base object.
Syntax
SuperExpression
super
super Arguments
Verification
SuperExpression : super
If frame is none
Throw a VerificationError
Call verifyType(obj,limit)
Evaluation
SuperExpression : super
72
14 Expressions
Else
Compatibility
This differs from ActionScript 3.0 depending on the value of this , and whether the
value of constructor , prototoype or __proto__ has been modified.
Syntax
PostfixExpression
FullPostfixExpression
ShortNewExpression
FullPostfixExpression
PrimaryExpression
FullNewExpression
73
14 Expressions
FullPostfixExpression PropertyOperator
SuperExpression PropertyOperator
FullPostfixExpression Arguments
FullPostfixExpression QueryOperator
Verification
FullPostfixExpression : PrimaryExpression
FullPostfixExpression : FullNewExpression
Return the result of verifying the right hand side of the production
If isStrict()
Call verifyType(fun,Function)
74
14 Expressions
Call verifyType(type,Number)
Evaluation
FullPostfixExpression : PrimaryExpression
FullPostfixExpression : FullNewExpression
75
14 Expressions
Call writeReference(ref,num2)
Return num1
Call writeReference(ref,num2)
Return num1
A new expression results in the invocation of the intrinsic construct method of the value
computed by the expression that follows the new keyword. Arguments, if specified, are
passed to the construct method. If no arguments are specified, the parentheses may be
omitted.
Syntax
FullNewExpression
76
14 Expressions
FullNewSubexpression
PrimaryExpression
FullNewExpression
FullNewSubexpression PropertyOperator
SuperExpression PropertyOperator
A FullNewSubexpression may be used between the new keyword and the Arguments in
a FullNewExpression, before a PropertyOperator in another FullNewSubexpression, or as
a ShortNewSubexpression.
ShortNewExpression
new ShortNewSubexpression
ShortNewSubexpression
FullNewSubexpression
ShortNewExpression
Verification
If isStrict()
Call verifyType(fun,Function)
FullNewSubexpression : PrimaryExpression
77
14 Expressions
FullNewSubexpression : FullNewExpression
Return the result of verifying the non-terminal symbol on the right-hand side of the
production
ShortNewSubexpression : FullNewSubexpression
ShortNewSubexpression : ShortNewExpression
Return the result of verifying the non-terminal symbol on the right-hand side of the
production
Evaluation
FullNewSubexpression : PrimaryExpression
FullNewSubexpression : FullNewExpression
78
14 Expressions
ShortNewSubexpression : FullNewSubexpression
ShortNewSubexpression : ShortNewExpression
Syntax
PropertyOperator
. QualifiedIdentifier
Brackets
Brackets
[ ListExpressionallowIn ]
Verification
PropertyOperator : . QualifiedIdentifier
79
14 Expressions
PropertyOperator : Brackets
Brackets : [ ListExpression ]
Verify ListExpression
Evaluation
PropertyOperator : . QualifiedIdentifier
PropertyOperator : Brackets
Brackets : [ ListExpression ]
Else
Return name
Syntax
QueryOperator
.. QualifiedIdentifier
. ( ListExpressionallowIn )
Verification
QueryOperator : .. QualifiedIdentifier
80
14 Expressions
Call verifyType(type,XML)
Verify QualifiedIdentifier
QueryOperator: . ( ListExpression )
Call verifyType(type,XML)
Verify ListExpression
Evaluation
Syntax
Arguments
()
( ListExpressionallowIn )
ArgumentListβ
AssignmentExpressionβ
ArgumentListβ , AssignmentExpressionβ
Verification
Arguments : ()
Arguments : ( ArgumentList )
81
14 Expressions
Return argTypes
ArgumentList : AssignmentExpression
Evaluation
Arguments : ()
Arguments : ( ArgumentList )
ArgumentList : AssignmentExpression
Call push(args,val)
Return
Call push(args,val)
Return
82
14 Expressions
Syntax
UnaryExpression
PostfixExpression
delete PostfixExpression
void UnaryExpression
typeof UnaryExpression
++ PostfixExpression
-- PostfixExpression
+ UnaryExpression
- UnaryExpression
- NegatedMinLong
~ UnaryExpression
! UnaryExpression
Verification
UnaryExpression : PostfixExpression
Verify PostfixExpression
Verify UnaryExpression
83
14 Expressions
Verify UnaryExpression
UnaryExpression : ++ PostfixExpression
UnaryExpression : -- PostfixExpression
UnaryExpression : + PostfixExpression
UnaryExpression : - PostfixExpression
Call verifyType(type,int)
UnaryExpression : - NegatedMinLong
UnaryExpression : ~ UnaryExpression
Call verifyType(type,int)
UnaryExpression : ! UnaryExpression
Call verifyType(type,Boolean)
Evaluation
UnaryExpression : PostfixExpression
84
14 Expressions
Else
Return true
Call readReference(ref)
Return undefined
Else
UnaryExpression : ++ PostfixExpression
Call writeReference(ref,num2)
Return num2
UnaryExpression : -- PostfixExpression
Call writeReference(ref,num2)
Return num2
85
14 Expressions
UnaryExpression : + PostfixExpression
UnaryExpression : - PostfixExpression
UnaryExpression : - NegatedMinLong
UnaryExpression : ~ UnaryExpression
UnaryExpression : ! UnaryExpression
If bool == true
Return false
Return true
The binary expressions are left associative and have relative precedence as specified in
the grammar: LogicalOrExpression has the lowest precedence
and MultiplicativeExpression has the highest precedence.
86
14 Expressions
Syntax
MultiplicativeExpression
UnaryExpression
MultiplicativeExpression * UnaryExpression
MultiplicativeExpression / UnaryExpression
MultiplicativeExpression % UnaryExpression
Verification
MultiplicativeExpression : UnaryExpression
Call verifyType(x,Number)
Call verifyType(y,Number)
Evaluation
MultiplicativeExpression : UnaryExpression
87
14 Expressions
Syntax
AdditiveExpression
MultiplicativeExpression
AdditiveExpression + MultiplicativeExpression
AdditiveExpression - MultiplicativeExpression
Verification
AdditiveExpression: MultiplicativeExpression
Return type *
88
14 Expressions
Call verifyType(x,Number)
Call verifyType(y,Number)
Evaluation
AdditiveExpression: MultiplicativeExpression
89
14 Expressions
Syntax
ShiftExpression
AdditiveExpression
Verification
ShiftExpression : AdditiveExpression
Call verifyType(x,Number)
Call verifyType(y,Number)
Evaluation
ShiftExpression : AdditiveExpression
90
14 Expressions
Syntax
RelationalExpressionallowIn
ShiftExpression
RelationalExpressionallowIn in ShiftExpression
RelationalExpressionallowIn is ShiftExpression
RelationalExpressionallowIn as ShiftExpression
91
14 Expressions
RelationalExpressionnoIn
ShiftExpression
RelationalExpressionnoIn is ShiftExpression
RelationalExpressionnoIn as ShiftExpression
Verification
RelationalExpression : ShiftExpression
Verify RelationalExpression
Call verifyType(type,Type)
92
14 Expressions
Verify RelationalExpression
Call verifyType(type,Type)
Evaluation
RelationalExpression : ShiftExpression
93
14 Expressions
94
14 Expressions
Syntax
EqualityExpressionβ
RelationalExpressionβ
EqualityExpressionβ == RelationalExpressionβ
EqualityExpressionβ != RelationalExpressionβ
The β notation signifies that both the allowIn and noIn variants are included.
Verification
EqualityExpression : RelationalExpression
Evaluation
EqualityExpression : RelationalExpression
95
14 Expressions
Syntax
BitwiseAndExpressionβ
EqualityExpressionβ
96
14 Expressions
BitwiseXorExpressionβ
BitwiseAndExpressionβ
BitwiseXorExpressionβ ^ BitwiseAndExpressionβ
BitwiseOrExpressionβ
BitwiseXorExpressionβ
BitwiseOrExpressionβ | BitwiseXorExpressionβ
Verification
BitwiseAndExpression : EqualityExpression
Call verifyType(x,Number)
Call verifyType(y,Number)
BitwiseXorExpression : BitwiseAndExpression
Call verifyType(x,Number)
Call verifyType(y,Number)
BitwiseOrExpression : BitwiseXorExpression
97
14 Expressions
BitwiseAndExpression : EqualityExpression
BitwiseXorExpression : BitwiseAndExpression
BitwiseOrExpression : BitwiseXorExpression
98
14 Expressions
Syntax
LogicalAndExpressionβ
BitwiseOrExpressionβ
LogicalOrExpressionβ
LogicalAndExpressionβ
LogicalOrExpressionβ || LogicalXorExpressionβ
Verification
LogicalAndExpression: BitwiseOrExpression
LogicalOrExpression : LogicalAndExpression
Evaluation
LogicalAndExpression: BitwiseOrExpression
99
14 Expressions
LogicalOrExpression : LogicalAndExpression
Syntax
ConditionalExpressionβ
LogicalOrExpressionβ
Verification
ConditionalExpression : LogicalOrExpression
100
14 Expressions
Return type *
Evaluation
ConditionalExpression : LogicalOrExpression
Else
Syntax
NonAssignmentExpressionβ
LogicalOrExpressionβ
Verification
NonAssignmentExpression : LogicalOrExpression
Return type *
101
14 Expressions
Evaluation
NonAssignmentExpression : LogicalOrExpression
Else
Syntax
AssignmentExpressionβ
ConditionalExpressionβ
PostfixExpression = AssignmentExpressionβ
102
14 Expressions
CompoundAssignment
*=
/=
%=
+=
-=
<<=
>>=
>>>=
&=
^=
|=
LogicalAssignment
&&=
^^=
||=
Verification
Call verifyType(rhstype,lhstype)
Return rhstype
103
14 Expressions
Evaluation
Call writeReference(ref1,val)
Return val
Let val be the result of calling the operator method that corresponds to
CompoundAssignment or LogicalAssignment with arguments val1 and val2
Call writeReference(ref1,val)
Return val
Syntax
ListExpressionβ
AssignmentExpressionβ
ListExpressionβ , AssignmentExpressionβ
Verification
ListExpression : AssignmentExpression
104
14 Expressions
Verify ListExpression
Evaluation
ListExpression : AssignmentExpression
Evaluate ListExpression
Syntax
TypeExpressionβ
NonAssignmentExpressionβ
Verification
TypeExpression : AssignmentExpression
Return type *
105
14 Expressions
Evaluation
TypeExpression : AssignmentExpression
Throw TypeError
Return val
106
15 Statements
15 Statements
ω = {abbrev, noShortIf, full}
Syntax
Statement ω
SuperStatement Semicolon ω
Block
IfStatement ω
SwitchStatement
DoStatement Semicolon ω
WhileStatement ω
ForStatementw ω
WithStatement ω
ContinueStatement Semicolon ω
BreakStatement Semicolon ω
ReturnStatement Semicolon ω
ThrowStatement Semicolon ω
TryStatement
ExpressionStatement Semicolon ω
LabeledStatement ω
DefaultXMLNamespaceStatement
Substatement ω
EmptyStatement
Statement ω
SimpleVariableDefinition Semicolon ω
107
15 Statements
Substatements
«empty»
SubstatementsPrefix
«empty»
Semicolon abbrev
VirtualSemicolon
«empty»
Semicolon noShortIf
VirtualSemicolon
«empty»
Semicolonfull
VirtualSemicolon
Syntax
EmptyStatement
108
15 Statements
Verification
EmptyStatment : ;
Do nothing
Evaluation
Syntax
ExpressionStatement
Verification
ExpressionStatement : ListExpression
Verify ListExpression
Evaluation
ExpressionStatement : ListExpression
Syntax
SuperStatement
super Arguments
109
15 Statements
class B extends A {
function B(x,y,z) {
super(x,y)
// other constructor code here
}
}
Semantics
Compatibility
If used in a class instance function, it will call the class's constructor function using the
current value of this as the first argument. If used in global code, it will call the global
object's class's super constructor.
Syntax
Block
{ Directives }
Syntax
LabeledStatementω
Identifier : Substatementω
Verification
LabeledStatement : Substatement
110
15 Statements
Verify Substatement
Evaluation
LabeledStatement : Substatement
Try
Throw x
Compatibility
ActionScript 2.0 does not allow LabeledStatements. This is a compatible change to the
language.
15.6.1 If statement
Syntax
IfStatement abbrev
abbrev
if ParenListExpression Substatement
noShortIf abbrev
if ParenListExpression Substatement else Substatement
IfStatement full
full
if ParenListExpression Substatement
noShortIf full
if ParenListExpression Substatement else Substatement
IfStatement noShortIf
noShortIf noShortIf
if ParenListExpression Substatement else Substatement
111
15 Statements
Verification
Evaluation
Return cv
Syntax
SwitchStatement
CaseElements
«empty»
CaseLabel
112
15 Statements
CaseElementsPrefix
«empty»
CaseElement ω
Directive ω
CaseLabel
CaseLabel
allowIn
case ListExpression :
default :
Semantics
Switch statements have the same syntax and semantics as defined in ECMA-262 edition
3.
Syntax
DoStatement
Verification
113
15 Statements
Verify Substatement
Verify ParenListExpression
Evaluation
Try
Loop
Try
Throw x
Throw x
Syntax
WhileStatementw
114
15 Statements
Evaluation
Syntax
ForStatementw
115
15 Statements
ForInitializer
«empty»
ListExpressionnoIn
VariableDefinitionnoIn
ForInBinding
PostfixExpression
VariableDefinitionKind VariableBindingnoIn
OptionalExpression
ListExpressionallowIn
«empty»
Semantics
For statements in edition 4 have the same syntax and semantics as defined in ECMA-
262 edition 3 and E4X
Syntax
ContinueStatement
Continue
Verification
ContinueStatement : continue
116
15 Statements
Evaluation
ContinueStatement : continue
Compatibility
ActionScript 2.0 does not allow the second form of ContinueStatement. This is a
compatible change.
Syntax
BreakStatement
break
Verification
BreakStatement : break
117
15 Statements
Evaluation
BreakStatement: break
Compatibility
ActionScript 2.0 does not allow the second form of BreakStatement. This is a
compatible change.
Syntax
WithStatementw
Semantics
With statements have the same syntax and semantics as defined in ECMA-262 edition
3.
Syntax
ReturnStatement
Return
Verification
ReturnStatement : return
118
15 Statements
Verify ListExpression
Evaluation
BreakStatement: return
Syntax
ThrowStatement
Verification
Verify ListExpression
Evaluation
119
15 Statements
Syntax
TryStatement
CatchClausesOpt
«empty»
CatchClauses
CatchClauses
CatchClause
CatchClauses CatchClause
CatchClause
CatchClausesOpt : CatchClauses
CatchClauses : CatchClause
Verify each of the non-terminal symbols on the right-hand side of the production
120
15 Statements
Evaluation
Try
Catch if exception x is of type Object (note: excludes Return, Break and Continue
exceptions)
Throw x
Try
Catch if exception x is of type Object (note: excludes Return, Break and Continue
exceptions)
Try
Catch if exception x
Evaluate Block2
CatchClausesOpt : empty
121
15 Statements
Return none
CatchClausesOpt : CatchClauses
CatchClauses : CatchClause
Syntax
DefaultXMLNamespaceStatement
default [no line break] xml [no line break] namespace = NonAssignmentExpressionb
Semantics
122
16 Directives
16 Directives
Syntax
Directivew
EmptyStatement
Statementw
AnnotatableDirectivew
IncludeDirective Semicolonw
ImportDirective Semicolonw
UseDirective Semicolonw
AnnotatableDirectivew
VariableDefinitionallowIn Semicolonw
FunctionDefinition
ClassDefinition
InterfaceDefinition
NamespaceDefinition Semicolonw
Directives
«empty»
DirectivesPrefix Directiveabbrev
DirectivesPrefix
«empty»
DirectivesPrefix Directivefull
123
16 Directives
16.1 Attributes
Syntax
Attributes
Attribute
AttributeCombination
AttributeCombination
Attribute
AttributeExpression
ReservedNamespace
[ AssignmentExpressionallowIn ]
AttributeExpression
Identifier
AttributeExpression PropertyOperator
124
16 Directives
Semantics
The meaning of an Attribute depends on its compile-time value and its usage. See the
description of the definitions being modified by the attribute.
Syntax
ImportDirective
import PackageName . *
Semantics
An ImportDirective causes the simple and fully qualified names of one or more public
definitions of the specified package to be introduced into the current package. Simple
names will be shadowed by identical locally defined names. Ambiguous references to
imported names result in runtime errors.
The wildcard form (import a.b.*) imports all public names in a package. The single
name form (import a.b.x) imports only the specified name.
The mechanism for locating and loading imported packages is implementation defined.
Compatibility
The ActionScript 2.0 behavior of raising an error if there are two classes with the same
simple name being imported is deprecated. ActionScript 3.0 will import both classes,
but references to the shared simple class name will result a compile-time error. Such
references must be disambiguated by using a fully qualified class name.
The ActionScript 2.0 behavior of implicit import is also deprecated and will result in a
compile-time error in ActionScript 3.0. To work around such errors, an explicit import
directive must be added to the current package, which imports the referenced class.
125
16 Directives
Syntax
IncludeDirective
Semantics
Compatibility
In ActionScript 2.0, the include keyword is spelled #include . This form is deprecated
and results in a compile warning in ActionScript 3.0.
Syntax
UseDirective
Semantics
Compatibility
126
17 Definitions
17 Definitions
Syntax
VariableDefinitionb
VariableDefinitionKind VariableBindingListb
VariableDefinitionKind
var
const
VariableBindingListb
VariableBindingb
VariableBindingListb , VariableBindingb
VariableBindingb
TypedIdentifierb VariableInitialisationb
VariableInitialisationb
«empty»
= VariableInitialiserb
VariableInitialiserb
AssignmentExpressionb
AttributeCombination
TypedIdentifierb
Identifier
Identifier : TypeExpressionb
127
17 Definitions
Semantics
protected accessible from within an instance of the current class or a derived classes
Compatibility
Typed identifier behavior differs between ActionScript 3.0 and ActionScript 2.0 in two
ways. ActionScript 2.0 checks for type compatibility using compile-time types at
compile time, while ActionScript 3.0 checks for type compatibility using runtime types
at runtime. The difference can be seen in the following examples:
var s : String = o
function f( s : String ) {}
var o = 10
f(o) // OK in ActionScript 2.0, error in ActionScript 3.0
In ActionScript 2.0, the variable o does not have an explicit compile-time type that can
be compared to the type String of the parameter s in the call to function f , so no error
is reported. In ActionScript 3.0, the value of argument o is compared to the type of the
parameter s at runtime, resulting in an error.
class A {}
class B extends A { var x }
var a : A = new B
a.x = 20 // Error in ActionScript 2.0, OK in ActionScript 3.0 (since
instance of B has an x property)
128
17 Definitions
In ActionScript 2.0, the compiler uses A, the declared type of a , to conservatively check
for valid uses of a , excluding completely safe and reasonable uses of a . In ActionScript
3.0, the compiler uses the type of a to optimize its use, but does not report type errors.
It leaves that task to the runtime.
Syntax
FunctionDefinition
Semantics
A FunctionDefinition introduces a new name and binds that name to a newly created
function object specified by FunctionCommon. The implementation of the function
object depends on whether the function is static or virtual as indicated by its context
and attributes.
129
17 Definitions
Syntax
FunctionName
Identifier
Semantics
FunctionName specifies at compile time the name and kind of function being defined. A
name that includes a get or set modifier specifies that the function being defined is a
property accessor.
Syntax
FunctionCommon
FunctionSignature
FunctionSignature Block
Verification
Evaluation
130
17 Definitions
Syntax
FunctionSignature
( ) ResultType
( Parameters ) ResultType
Semantics
The function signature defines the set of traits associated with the activation of a
function object.
In the strict dialect, the Arguments assigned to Parameters must have compatible
number and types. In the standard dialect, the handling of arguments is the same as
edition 3.
Syntax
Parameters
«empty»
NonemptyParameters
NonemptyParameters
Parameter
Parameter , NonemptyParameters
RestParameter
Parameter
TypedIdentifierallowIn
TypedIdentifierallowIn = AssignmentExpressionallowIn
131
17 Definitions
RestParameter
...
... Identifier
Verification
Parameters : empty
Do nothing
Parameters : NonemptyParameters
Verify NonemptyParameters
NonemptyParameters : Parameter
Verify Parameter
Call defineSlotTrait(frame,name,type,false)
Verify Parameter
Call defineSlotTrait(frame,name,type,false)
NonemptyParameters : RestParameter
Verify RestParameter
Parameter : TypedIdentifier
Verify TypedIdentifier
132
17 Definitions
Call defineSlotTrait(frame,name,type,undefined,false)
Verify TypedIdentifier
Verify AssignmentExpression
Call defineSlotTrait(frame,name,type,val,false)
RestParameter : …
Do nothing
RestParameter : … Identifier
Verify Identifier
Call defineSlotTrait(frame,name,Array,false)
Syntax
ResultType
«empty»
: TypeExpressionallowIn
Semantics
ResultType guarantees the type of the value returned from a function. It is a verify
error if the return value does not implicitly convert to the ResultType of the function.
133
17 Definitions
Compatibility
The ActionScript 2.0 behavior of checking types only at compile time is more permissive
than in ActionScript 3.0. This will result in new runtime errors in cases such as calling
the method shown above with an argument of type String.
Syntax
ClassDefinition
The default attributes for a class definition are internal, non-dynamic, and non-final.
Semantics
A class definition adds a new class name into the current scope. In the following
drawing, the class name A refers to a class object with the structure shown in the
drawing:
class A {}
134
17 Definitions
A class definition causes a class object and prototype instance to be created. The
default delegate of the instance prototype is the Object prototype. The default super
class of the class object is the Object class. Static members are added to the class
object as fixed properties, and non-static members are added to the instance prototype
as fixed properties. The internal references (traits, prototype, constructor, and
delegate) between these objects are read-only.
Syntax
ClassName
ClassIdentifiers
ClassIdentifiers
Identifier
ClassIdentifiers . Identifier
Semantics
135
17 Definitions
Compatibility
Syntax
Inheritance
«empty»
extends TypeExpressionallowIn
implements TypeExpressionList
TypeExpressionList
TypeExpressionallowIn
TypeExpressionList , TypeExpressionallowIn
Semantics
A ClassDefinition may extend another class definition and implement one or more
interfaces. We say that a class inherits the properties of its base class and the abstract
methods of its interfaces. When a class extends another class, it is inherits the base
class's instance properties, but not its static properties. When a class implements one
or more interfaces it is required to define each inherited interface method.
The TypeExpressions that occur in the extends and implements clauses must be
compile-time constant expressions without forward references.
Syntax
The body of a class definition is syntactically a Block. The class block must come
immediately after the ClassName or Inheritance constituents, if present. The class block
must not contain a ClassDefinition or InterfaceDefinition.
136
17 Definitions
Semantics
Declarations modified by the static attribute contribute properties to the class object;
declarations without the static attribute contribute properties to the instance traits
object. Statements that are not declarations are evaluated normally when the class
object is instantiated.
17.3.4.1 Variables
protected Visible to references inside an instance of the current class and derived classes
AttributeExpression Namespace value is the qualifier for the name of the definition
The default attributes for variable definitions are non-static and internal.
17.3.4.2 Methods
protected Visible to references inside instances of the current class and derived classes
AttributeExpression Namespace value is the qualifier for the name of the definition
The default attributes for function definitions in a class are non-static , non-final, non-
native and internal.
137
17 Definitions
Methods that implement interface methods must be instance methods defined with
attributes that include public . Interface methods may be overridden in a derived class
as long as the overriding method also has the public attribute.
A constructor method is a method with the same name as the class it is defined in. It is
a syntax error for the constructor method to have a different namespace attribute than
its class.
It is a verifier error for override to appear as an attribute of a class method that does
not override another method.
Syntax
InterfaceDefinition
Semantics
Compatibility
In ActionScript 2.0, user-defined types only exist at compile time. Therefore, any use of
an interface name that cannot be enforced at compile time will have no effect on the
program. See descriptions of ResultType and TypeIdentifier.
138
17 Definitions
The name of an interface definition has the syntax and semantics of a ClassName
(section 16.3.1).
Syntax
ExtendsList
«empty»
extends TypeExpressionList
Semantics
An interface definition must not introduce a method with a name that has the same
identifier as an inherited method.
The body of an interface definition is syntactically a Block, but must only contain
FunctionDefinitions with no Block and no attribute.
Interface methods must be defined with no attribute. An interface method is given the
name that has its interface as its qualifier and the identifier as the string.
139
17 Definitions
Syntax
PackageDefinition
Semantics
A PackageDefinition introduces a new package name into the current scope. A package
definition causes the public members of that package to be qualified by the package
name, and the internal members of that package definition to be qualified by an
anonymous namespace that is only accessible to code inside the package.
The statements of a package body are executed in the global scope of the Program.
Compatibility
Syntax
PackageName
Identifier
PackageName . Identifier
140
17 Definitions
Syntax
NamespaceDefinition
namespace NamespaceBinding
NamespaceBinding
Identifier NamespaceInitialisation
NamespaceInitialisation
«empty»
= AssignmentExpressionallowIn
Semantics
141
17 Definitions
Syntax
Program
Directives
PackageDefinition Program
package P {
function f() {}
}
package Q {
function f() {}
}
P.f()
Q.f()
142
18 Errors
18 Errors
The following errors may occur while parsing or verifying a class definition:
Defining a class with the name of another definition in the same scope
Defining a constructor that calls its super constructor more than once
Overriding a variable
The following errors may occur while parsing or verifying an interface definition:
Defining an interface with the name of another definition in the same scope
Defining an interface with a body that contain a definition or statement other than
a function definition with no block
143
18 Errors
It is a strict error to import the same name more than once into the same package.
144
19 Native objects
19 Native objects
The form and function of the native objects is the same as ECMA-262 edition 3 except
that all prototype properties are also implemented as class methods. Prototype
properties that are functions are implemented as regular methods. Prototype properties
that are variables are implemented as a pair of get and set methods that forward state
to the prototype property.
Global object
NaN
Infinity
undefined
parseInt
parseFloat
isNaN
isFinite
decodeURI
decodeURIComponent
encodeURI
encodeURIComponent
145
19 Native objects
Object object
Object
Object.prototype
Object.prototype.constructor
Object.prototype.toString
Object.prototype.toLocaleString
Object.prototype.valueOf
Object.prototype.hasOwnProperty
Object.prototype.isPrototypeOf
Object.prototype.propertyIsEnumerable
Function object
Function
Function.prototype
Function.prototype.constructor
Function.prototype.toString
Function.prototype.apply
Function.prototype.call
Function.length
Function.prototype
146
19 Native objects
Array object
Array
Array.prototype
Array.prototype.constructor
Array.prototype.toString
Array.prototype.toLocaleString
Array.prototype.concat
Array.prototype.join
Array.prototype.pop
Array.prototype.push
Array.prototype.reverse
Array.prototype.shift
Array.prototype.slice
Array.prototype.sort
Array.prototype.splice
Array.prototype.unshift
Array.[[Put]]
Array.length
147
19 Native objects
String object
String
String.prototype
String.fromCharCode
String.prototype.constructor
String.prototype.toString
String.prototype.valueOf
String.prototype.charAt
String.prototype.charCodeAt
String.prototype.concat
String.prototype.indexOf
String.prototype.lastIndexOf
String.prototype.localeCompare
String.prototype.match
String.prototype.replace
String.prototype.search
String.prototype.slice
String.prototype.split
String.prototype.substring
String.prototype.toLowerCase
String.prototype.toLocaleLowerCase
String.protoype.toUpperCase
String.protoype.toLocaleUpperCase
String.[[Value]]
String.length
148
19 Native objects
Boolean object
Boolean
Boolean.prototype
Boolean.prototype.constructor
Boolean.prototype.toString
Boolean.prototype.valueOf
Number object
Number
Number.prototype
Number.MAX_VALUE
Number.MIN_VALUE
Number.NaN
Number.NEGATIVE_INFINITY
Number.POSITIVE_INFINITY
Number.protoype.constructor
Number.protoype.toString
Number.prototype.toLocaleString
Number.prototype.valueOf
Number.prototype.toFixed
Number.prototype.toExponential
Number.prototype.toPrecision
149
19 Native objects
Math object
Math.E
Math.LN10
Math.LN2
Math.LOG2E
Math.LOG10E
Math.PI
Math.SQRT1_2
Math.SQRT2
Math.abs
Math.acos
Math.asin
Math.atan
Math.atan2
Math.ceil
Math.cos
Math.exp
Math.floor
Math.log
Math.max
Math.min
Math.pow
Math.random
Math.round
Math.sin
Math.sqrt
Math.tan
150
19 Native objects
Date object
Date
Date.protoype
Date.parse
Date.UTC
Date.prototype.constructor
Date.prototype.toString
Date.prototype.toDateString
Date.prototype.toTimeString
Date.prototype.toLocaleString
Date.prototype.toLocaleDateString
Date.prototype.toLocaletimeString
Date.prototype.valueOf
Date.prototype.getTime
Date.prototype.getFullYear
Date.prototype.getUTCFullYear
Date.prototype.getMonth
Date.prototype.getUTCMonth
Date.prototype.getDate
Date.prototype.getUTCDate
Date.prototype.getDay
Date.prototype.getUTCDay
Date.prototype.getHours
Date.prototype.getUTCHours
Date.prototype.getMinutes
Date.prototype.getUTCMinutes
Date.prototype.getSeconds
151
19 Native objects
Date object
Date.prototype.getUTCSeconds
Date.prototype.getMilliseconds
Date.prototype.getUTCMilliseconds
Date.prototype.getTimezoneOffset
Date.prototype.setTime
Date.prototype.setMilliseconds
Date.prototype.setUTCMilliseconds
Date.prototype.setSeconds
Date.prototype.setUTCSeconds
Date.prototype.setMinutes
Date.prototype.setUTCMinutes
Date.prototype.setHours
Date.prototype.setUTCHours
Date.prototype.setDate
Date.prototype.setUTCDate
Date.prototype.setMonth
Date.prototype.setUTCMonth
Date.prototype.setFullYear
Date.prototype.setUTCFullYear
Date.prototype.toUTCString
152
19 Native objects
Error object
Error
Error.prototype
Error.prototype.constructor
Error.prototype.name
Error.prototype.message
Error.prototype.toString
153
20 Compatibility with the static profile
154
21 Compatibility with ECMAScript edition 3
In ECMA-262 edition 3, primitive values (Boolean, Number, String) are boxed in Object
values in various contexts. In ActionScript 3.0, primitives are permanently sealed
Objects. Unlike boxed objects, attempts to dynamically extend a sealed object results in
a runtime exception.
155
22 Compatibility with E4X
156