class Person {
public static var numPeople:Number = 0;
// instance members
private var _speed:Number;
// constructor
public function Person(speed:Number) {
Person.numPeople++;
this._speed = speed;
}
// static methods
public static function getPeople():Number {
return Person.numPeople;
}
// instance methods
public function walk(speed:Number):Void {
this._speed = speed;
}
public function run():Void {
this._speed *= 2;
}
public function rest():Void {
this._speed = 0;
}
// getters/setters (accessor methods)
public function get speed():Number {
return this._speed;
}
}
For a full demonstration of how to write methods like the ones in the previous code sample,
see
Chapter 7, "Classes," on page
to a class that is built into the ActionScript language. MovieClip and Math are examples of
top-level classes that you might use in an application. When you use methods from these
classes in your code, they are functions written in the built-in class (similar to the previous
code sample). Alternatively, you could use methods from a custom class that you
wrote yourself.
Functions that don't belong to a class are called top-level functions (sometimes called predefined
or built-in functions), meaning that you can call them without a constructor. Examples of
functions that are built in to the top level of the ActionScript language are
.
setInterval()
204
Functions and Methods
225. The methods that you use in your code might belong
and
trace()
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?