MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 800

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Objects in ActionScript can be pure containers for data, or they can be graphically represented on
the Stage as movie clips, buttons, or text fields. All movie clips are instances of the built-in class
MovieClip, and all buttons are instances of the built-in class Button. Each movie clip instance
contains all the properties (for example,
methods (for example,
To define a class, you create a special function called a constructor function. (Built-in classes have
built-in constructor functions.) For example, if you want information about a bicycle rider in
your application, you could create a constructor function,
and the method
distance
function Biker(t, d) {
this.time = t;
this.distance = d;
this.getSpeed = function() {return this.time / this.distance;};
}
In this example, you create a function that needs two pieces of information, or parameters, to do
its job:
and
. When you call the function to create new instances of the object, you pass it the
t
d
parameters. The following code creates instances of the object Biker called
emma = new Biker(30, 5);
hamish = new Biker(40, 5);
In object-oriented scripting, classes can receive properties and methods from each other according
to a specific order; this is called inheritance. You can use inheritance to extend or redefine the
properties and methods of a class. A class that inherits from another class is called a subclass. A
class that passes properties and methods to another class is called a superclass. A class can be both a
subclass and a superclass.
An object is a complex data type containing zero or more properties and methods. Each property,
like a variable, has a name and a value. Properties are attached to the object and contain values
that can be changed and retrieved. These values can be of any data type: String, Number,
Boolean, Object, MovieClip, or undefined. The following properties are of various data types:
customer.name = "Jane Doe";
customer.age = 30;
customer.member = true;
customer.account.currentRecord = 000609;
customer.mcInstanceName._visible = true;
The property of an object can also be an object. In line 4 of the previous example,
property of the object
data type of the
Creating a custom object in ActionScript 1
To create a custom object, you define a constructor function. A constructor function is always
given the same name as the type of object it creates. You can use the keyword
body of the constructor function to refer to the object that the constructor creates; when you call
a constructor function, Flash passes it
constructor function that creates a circle with the property
function Circle(radius) {
this.radius = radius;
}
800
Appendix E: Object-Oriented Programming with ActionScript 1
gotoAndPlay()
getSpeed()
and
customer
currentRecord
property is Number.
currentRecord
this
,
_height
_rotation
,
,
loadMovie()
startDrag()
Biker()
, which tells you how fast the biker is traveling:
is a property of the object
as a hidden parameter. For example, the following is a
radius
,
) and all the
_totalframes
) of the MovieClip class.
, with the properties
and
emma
account
account
inside the
this
:
and
time
.
hamish
is a
. The

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Table of Contents