|
|
||||||||
| Ultrashock Tutorials > Flash MX 2004 > ActionScript 2.0 | ||||||||
|
||||||||
|
|
ActionScript 2.0 |
|
||||||
06. Private or Protected?One important note to make is the implementation of private in ActionScript 2.0. In languages such as Java, a private member means that only the class itself has access to it, and no access from a subclass (whether it is from the same package or not). In AS2, the implementation of private behaves more like protected in other languages; the scope is extended to subclass(es). Because these new modifiers are checked at compile-time only, it is important to ensure that the compiler catches access to private methods and properties; this is only possible if strict-typing is used in the instance. For example, if we declare a property as private: class PrivateMemberClass {
private var privateProp:String = "I'm a private property";
}
The private property named 'privateProp' can be accessed if the instance is not typed: var instance = new PrivateMemberClass(); trace(instance.privateProp); // output "I'm a private property"On the other hand, if the instance is typed, the private property is inaccessible: var instance:PrivateMemberClass = new PrivateMemberClass(); trace(instance.privateProp); // compile error
|
| - discuss this tutorial - |