MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 25

Actionscript language reference
Table of Contents

Advertisement

function welcome(firstName:String, age:Number){
}
// strict typing of parameter and return value
function square(x:Number):Number {
var squared:Number = x*x;
return squared;
}
Because you must use the
global variable (see
You can declare the data type of objects based on built-in classes (Button, Date, MovieClip, and
so on) and on classes and interfaces that you create. In the following example, if you have a file
named Student.as in which you define the Student class, you can specify that objects you create
are of type Student:
var student:Student = new Student();
You can also specify that objects are of type Function or Void.
Using strict data typing helps ensure that you don't inadvertently assign an incorrect type of value
to an object. Flash checks for typing mismatch errors at compile time. For example, suppose you
type the following code:
// in the Student.as class file
class Student {
var status:Boolean; // property of Student objects
}
// in a script
var studentMaryLago:Student = new Student();
studentMaryLago.status = "enrolled";
When Flash compiles this script, a "Type mismatch" error is generated because the SWF file is
expecting a Boolean value.
Using strict typing also helps to ensure that you do not attempt to access properties or methods
that are not part of an object's type.
Casting objects
ActionScript lets you cast one data type to another. The cast operator that Flash uses takes the
form of a function call and is concurrent with explicit coercion, as specified in the ECMA-262
Edition 4 proposal (see www.mozilla.org/js/language/es4/index.html). Casting lets you assert that
an object is of a certain type so that when type-checking occurs, the compiler treats the object as
having a set of properties that its initial type does not contain. This can be useful, for example,
when iterating over an array of objects that might be of differing types but share a base type.
keyword when strictly typing variable, you can't strictly type a
var
"Scoping and declaring variables" on page
28).
Assigning data types to elements
25

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flex

Table of Contents