Objects And Classes - Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual

Programming actionscript 3.0
Table of Contents

Advertisement

Objects and classes

In ActionScript 3.0, every object is defined by a class. A class can be thought of as a template
or a blueprint for a type of object. Class definitions can include variables and constants, which
hold data values, and methods, which are functions that encapsulate behavior bound to the
class. The values stored in properties can be primitive values or other objects. Primitive values
are numbers, strings, or Boolean values.
ActionScript contains a number of built-in classes that are part of the core language. Some of
these built-in classes, such as Number, Boolean and String, represent the primitive values
available in ActionScript. Others, such as the Array, Math, and XML classes, define more
complex objects that are part of the ECMAScript standard.
All classes, whether built-in or user-defined, derive from the Object class. For programmers
with previous ActionScript experience, it is important to note that the Object data type is no
longer the default data type, even though all other classes still derive from it. In ActionScript
2.0, the following two lines of code were equivalent because the lack of a type annotation
meant that a variable would be of type Object:
var someObj:Object;
var someObj;
ActionScript 3.0, however, introduces the concept of untyped variables, which can be
designated in the following two ways:
var someObj:*;
var someObj;
An untyped variable is not the same as a variable of type Object. The key difference is that
untyped variables can hold the special value
cannot hold that value.
You can define your own classes using the
three ways: constants can be defined with the
keyword, and getter and setter properties are defined by using the
var
in a method declaration. You can declare methods with the
You create an instance of a class by using the
instance of the Date class called
var myBirthday:Date = new Date();
undefined
keyword. You can declare class properties in
class
keyword, variables are defined with the
const
operator. The following example creates an
new
.
myBirthday
, while a variable of type Object
and
get
keyword.
function

Objects and classes

attributes
set
37

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents