Game Development Reference
In-Depth Information
An example of a private method:
private function respawn(delta:Number):void {
}
A public method that returns a value:
public function isAlive():Boolean {
return ( m_life > 0);
}
Property and method access
We will learn a great deal about inheritance in the next section, but here is a pretty
picture that shows how private, protected, and public keyword usage on
properties and methods helps you control their access across classes.
Class A:
private var a: int;
publicvar b: int;
protected var c: int;
May access public
properties and methods
May access public
& protected
properties and
methods
private function f1():void {}
publicfunction f2():void {}
protected function f3():void {}
Class C:
...
var instanceofA:A -= new A();
instanceofA.a = 10;
...
var instanceofB.b = new B();
instanceofB.a = 99;
Class B inherita A
function func():void {
c=100;
}
In the previous figure, Class A defines three properties a, b, and c, which are private,
public, and protected, respectively. Class B , which is a subclass of A , may freely
access and modify the public and protected variables of Class A as if it were its own,
though it may not access Class A's private properties. Class C , which is a not related
to Class A or B , may only access A's or B's public properties. Note that the inherited
public properties, such as A may be accessed via an instance of B even though it
is defined in A. This is because of the subclass definition that B inherits all public
and protected of its parent class. These access rules apply exactly the same way for
methods as it does for properties.
 
Search WWH ::




Custom Search