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 -

09. Overriding, Overwriting or Overloading?

It seems these terms cause some confusion among developers who are new to OOP. In ActionScript, we only have overriding and overwriting, but no overloading (two out of three ain't bad - Meat Loaf).

Overriding means that a method or property steps in front of another and accepts the call. In the Math2.max() example, the new max() method overrides the original one in Math.max() (but uses it internally). Usually, overriding works with more than one class, with the subclass method or property overriding the superclass's method or property. This is also a form of polymorphism, meaning that there is more than one form (implementation) of a method. (Basically, having the same method name do different things.)

Overwriting is different in that the original no longer exists -- it is written over by (replaced with) another file, class, method, or property. In the TestClass example above, this block of code overwrites/replaces the method in the instance:

w.method = function() {
   trace("New method");
};
Overloading (which is not a native feature of ActionScript) is another form of polymorphism. It usually refers to the ability to handle different types of data, or number of data, or operators working differently depending on the meaning of the data. The most common overloading use in ActionScript is a method with different number of parameters. Although not perfect, this can be handled by a switch statement used with the arguments and arguments.length properties.


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