MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH Manual page 270

Learning actionscript 2.0 in flash
Table of Contents

Advertisement

5.
Save both ActionScript files before you proceed.
To continue writing your class file, see
Adding methods and properties
To create the properties for the ClassA and ClassB classes, use the
variables.
The following three exercises are part of
on page
263. If you do not wish to progress through the example, you can download the
class files from
www.helpexamples.com/flash/learnas/classes/.
To add properties to the ClassA and ClassB classes:
1.
Open ClassA.as and ClassB.as in the Flash authoring tool.
2.
Modify the ClassA.as ActionScript file to match the following code (the changes to make
appear in boldface):
class com.macromedia.utils.ClassA {
static var _className:String;
function ClassA() {
trace("ClassA constructor");
}
}
The previous block of code adds a single new static variable,
the name of the current class.
3.
Modify the ClassB class and add the static variable so it is similar to the previous code.
4.
Save both ActionScript files before you proceed.
By convention, class properties are defined at the top of the class body. Defining
them at the top makes the code easier to understand, but isn't required.
You use the post-colon syntax (for example,
the variable declarations. This is an example of strict data typing. When you type a variable
using the
var variableName:variableType
any values assigned to that variable match the specified type. If the correct data type is not
used in the FLA file importing this class, the compiler throws an error. For more information
on strict data typing, see
270
Classes
"Adding methods and properties" on page
"Example: Writing custom classes"
var username:String
"About assigning data types and strict data typing" on page
var
_className
format, the ActionScript compiler ensures that
270.
keyword to define
, which contains
and
var age:Number
81.
) in

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash 8

Table of Contents