O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subclassing Built-in Classes

Just as we can create subclasses of our own custom classes, we can also create subclasses of any non-final built-in class, allowing us to implement specialized functionality based on an existing ActionScript class. For an example of extending the built-in Array class, see Programming ActionScript 3.0 → Core ActionScript 3.0 Data Types and Classes → Working with Arrays → Advanced Topics, in Adobe's Programming ActionScript 3.0. For an example of extending the built-in Flash runtime class, Shape, see the section "Custom Graphical Classes" in Chapter 20.

Some built-in ActionScript classes are simply collections of class methods and class variables—for example, the Math, Keyboard, and Mouse classes exist merely to store related methods and variables (e.g., Math.random( ) and Keyboard.ENTER). Such classes are known as static method libraries, and are typically declared final. Rather than extending these classes, you must distribute your own static method libraries separately. For example, rather than adding a factorial( ) method to a subclass of the Math class, you would create a custom class, say AdvancedMath, to hold your factorial( ) method. The AdvancedMath class cannot be related to the Math class via inheritance.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required