MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual page 158

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

Advertisement

To create the class file:
Create a new directory on your hard disk and name it PersonFiles. This directory will contain
1
all the files for this project.
Do one of the following:
2
Create a new file in your preferred text or code editor.
(Flash Professional only) Select File > New to open the New Document dialog box, select
ActionScript File from the list of file types, and click OK. The Script window opens with a
blank file.
Save the file as Person.as in the PersonFiles directory.
3
In the Script window, enter the following code:
4
class Person {
}
This is called the class declaration. In its most basic form, a class declaration consists of the
keyword, followed by the class name (Person, in this case), and then left and right curly
class
braces (
). Everything between the braces is called the class body and is where the class's
{}
properties and methods are defined.
Note: The name of the class (Person) matches the name of the AS file that contains it (Person.as).
This is very important; if these two names don't match, the class won't compile.
To create the properties for the Person class, use the
5
and
age
name
class Person {
var age:Number;
var name:String;
}
Tip: By convention, class properties are defined at the top of the class body, which makes the
code easier to understand, but this isn't required.
Notice the colon syntax (
declarations. This is an example of strict data typing. When you type a variable in this way
(
var variableName:variableType
assigned to that variable match the specified type. Although this syntax is not required, it is
good practice and can make debugging your scripts easier. (For more information, see
data typing" on page
158
Chapter 9: Creating Classes with ActionScript 2.0
, as shown below.
var age:Number
38.)
keyword to define two variables named
var
and
var name:String
), the ActionScript 2.0 compiler ensures that any values
) used in the variable
"Strict

Advertisement

Table of Contents
loading

Table of Contents