For example, the top-level Math class consists only of static methods and properties. To call
any of its methods, you don't create an instance of the Math class. Instead, you simply call the
methods on the Math class itself. The following code calls the
Math class:
var squareRoot:Number = Math.sqrt(4);
trace(squareRoot); // 2
The following code invokes the
of two numbers:
var largerNumber:Number = Math.max(10, 20);
trace(largerNumber); // 20
For more information on creating class members, see
"Using class members" on page
A sample file on your hard disk demonstrates how to create a dynamic menu with XML data
and a custom class file. The sample calls the ActionScript
two parameters: the path to the XML menu file and a reference to the current timeline. The
rest of the functionality resides in a custom class file, XmlMenu.as.
You can find the sample source file, xmlmenu.fla, in the Samples folder on your hard disk.
On Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\XML_Menu.
On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/XML_Menu.
About class members
Most of the members (methods and properties) discussed so far in this chapter are of a type
called instance members. For each instance member, there's a unique copy of that member in
every instance of the class. For example, the
instance member, because each person has a different e-mail address.
Another type of member is a class member. There is only one copy of a class member, and you
use it for the entire class. Any variable declared within a class, but outside a function, is a
property of the class. In the following example, the Person class has two properties,
, of type Number and String, respectively:
username
class Person {
public var age:Number;
public var username:String;
}
250
Classes
method of the Math class, which determines the larger
max()
254.
member variable of the Sample class has an
email
method of the
sqrt()
"About class members" on page 250
constructor and passes it
XmlMenu()
and
and
age
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?