1 Tutorial introduction2
1 Tutorial introduction
An ActionScript program consists of zero or more package definitions followed by zeroor more directives, which includes non-package definitions and statements. Statementsinside and outside of package definitions are evaluated in order, independent of theirnesting inside a package.
1.1 Hello world
The following sections show various ways to implement simple programs such as thefamiliar 'hello, world' program in ActionScript 3.0:
trace("hello, world");
This is a single expression statement that calls a function named
trace()
with theargument that is a literal string
"hello, world"
. An expression statement doesnothing but execute an expression.
1.2 Expressions
Here are some examples of expressions:
x = 1 + 2x = y()x = y..zx = o.ns::id
Expressions evaluate to values:
1+2
evaluates to
3
.
y()
evaluates to the result of calling the function
y
with no arguments.
y..z
evaluates to the set of all properties identified by
z
in the value of
y
and thedescendants of
y
. The descendants accessor operator (..) is part of the ActionScript3.0 implementation of ECMAScript for XML (E4X).
o.ns::id
evaluates to the value of the property
ns::id
of the value of
o
,where
o
represents an object,
ns
represents a namespace, and
id
represents anidentifier.
1.3 Statements
Statements are executed in the order that they appear in a block. Some statementschange 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);}