Macromedia flex 2-migrating applications to flex 2 Manual De Usuario

Descargar
Página de 184
38
ActionScript 2.0 to 3.0
Constants
You can use the 
const
 keyword to define constants in ActionScript 3.0. First, you determine 
which class and instance variables qualify as constants, and then declare them with 
const
 
instead of 
var
; for example:
static const NONMODAL:Number = Alert.NONMODAL;
const backgroundColorName:String = "buttonColor";
In general, constants should be class constants rather than instance constants.
The initial value for a constant must be an expression that can be evaluated at compile time. 
Also, you cannot create constants of type Array or Object.
Method signatures
This section describes changes to method signatures in ActionScript 3.0.
No arguments
If a function takes no arguments, be sure to specify its argument list as 
()
 and not as 
(void)
The latter specifies a single argument of type Object named “void”. Consider which, if any, of 
the arguments should be optional, and assign default values for them; for example:
override public function createClassObject(type:Class, name:String=null, 
depth:int=0, initObj:Object=null):UIObject
Variable number of arguments
If the function takes a variable number of arguments, use the new “...” syntax:
function function_name([ arguments ], ... arrayOfArgs)
For example:
function foo(n:Number, ... arrayOfArgs):void
The “
...
” and its array must be the last argument in the method. You cannot specify a type 
because it is always an Array containing the other arguments.
The following example shows how to use a method with a variable number of arguments. If 
you define the following:
function myfunc(arg1, ... arrayOfArgs)
you can call it as:
myfunc(a, b, c, d);
and the Array arrayOfArgs will have the value 
[ b, c, d ]
.