Operators
177
Example
Usage 1: The following example declares a public variable named
userName
whose type is
String and assigns an empty string to it:
var userName:String = "";
Usage 2: The following example shows how to specify a function's parameter type by defining
a function named
randomInt()
that takes a parameter named
integer
of type Number:
function randomInt(integer:Number):Number {
return Math.round(Math.random()*integer);
}
trace(randomInt(8));
Usage 3: The following example defines a function named
squareRoot()
that takes a
parameter named
val
of the Number type and returns the square root of
val
, also a Number
type:
function squareRoot(val:Number):Number {
return Math.sqrt(val);
}
trace(squareRoot(121));
See also
var statement
,
function statement
typeof operator
typeof(
expression
)
The
typeof
operator evaluate the
expression
and returns a string specifying whether the
expression is a
String, MovieClip, Object, Function, Number,
or
Boolean
value.
Availability:
ActionScript 1.0; Flash Lite 2.0
Operands
expression :
Object
- A string, movie clip, button, object, or function.
Returns
String
- A
String
representation of the type of
expression
. The following table shows the
results of the
typeof
operator on each type of
expression
.
Expression Type
Result
String
string
Movie clip
movieclip
Summary of Contents for FLASHLITE2 ACTIONSCRIPT-LANGUAGE
Page 1: ...Flash Lite 2 x ActionScript Language Reference...
Page 22: ...22 Contents...
Page 244: ...244 ActionScript language elements...
Page 760: ...760 ActionScript classes...