Ultrashock Tutorials > Flash MX 2004 > ActionScript 2.0  
 
by Dave Yang, quantumwave.com - swfoo.com
Download Source Files 
 
ActionScript 2.0
 

01. Introduction
02. A little bit of OOP in ActionScript 1.0 
03. What's new in ActionScript 2.0?

04. New keywords and features for OOP
05. Scope and "this"
06. Private or protected?
07. Dynamic vs Static classes

08 Inheritance.
09. Overriding, Overwriting or Overloading?

10. Importing external class files
11. Interface
12. What is missing in ActionScript 2.0?
13. Conclusion

- discuss this tutorial -

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


This is one of the most common mistakes that people make and then wonder why private members are accessible. So now you know!


- discuss this tutorial -
 
©2003 Ultrashock.com - All rights reserved