Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 102

Programming actionscript 3.0
Table of Contents

Advertisement

// output:
// 1
// 2
// 3
The ... (rest) parameter can also be used with other parameters, as long as it is the last
parameter listed. The following example modifies the
first parameter,
, is of type int, and the second parameter uses the ... (rest) parameter. The
x
output skips the first value because the first parameter is no longer part of the array created by
the ... (rest) parameter.
function traceArgArray(x: int, ... args)
{
for (var i:uint = 0; i < args.length; i++)
{
trace(args[i]);
}
}
traceArgArray(1, 2, 3);
// output:
// 2
// 3
Functions as objects
Functions in ActionScript 3.0 are objects. When you create a function, you are creating an
object that can not only be passed as a parameter to another function, but also have properties
and methods attached to it.
Functions passed as arguments to another function are passed by reference and not by value.
When you pass a function as an argument, you use only the identifier and not the parentheses
operator that you use to call the method. For example, the following code passes a function
named
clickListener()
addEventListener(MouseEvent.CLICK, clickListener);
The
method also defines a parameter that accepts a function. For an example
Array.sort()
of a custom sort function that is used as an argument to the
"Sorting an array" on page
102
ActionScript Language and Syntax
as an argument to the
231.
traceArgArray()
addEventListener()
Array.sort()
function so that its
method:
function, see

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents