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 -

08. Inheritance

As mentioned above, inheritance is an important part of object-oriented programming (although it is not absolutely necessary). It is used to define the relationship that a subclass is a specialization of the superclass. ActionScript 2.0 introduces a new keyword for just this purpose: extends. In the Math2.max() example above, we've already seen it being used to inherit from Math. It's just that simple! No more debates on whether using new or __proto__ is better. What a relief!

Note that the keyword super() should be the first statement in the constructor (Flash MX 2004 actually warns you if it is not). However, Flash is also smart enough to insert it for you if you forget about it. If the superclass has no constructor, Flash generates one automatically.

Another relief is that the long-time bug with new inheritance is fixed in Flash Player 7 (behaviour remains the same in Flash Player 6). For those who are not familiar with this bug, see the issues listed in the section titled A little bit of OOP in ActionScript 1.0, above.

Just like all things that are "free" (as in Flash inserting super() for you), there's also a catch. If your subclass needs to pass argument(s) to the superclass, make sure you put in your own super(argument1, argument2...) statement. Otherwise, you'll wonder why only some of the parameters are being used. For example, if we were to create a subclass called Child that inherits from the Parent class (see above), we'd do something like this in the constructor:


class Child extends Parent { private var fName:String = ""; public function Child(lname:String, fname:String) { super(lname); // continue Child's constructor code fName = fname; } }

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