Introduction
Objects
Instances
Local
Inheritance
Prototypes
Override
Overwrite
Protection
Arguments
Constructors
Methods
Proto
Arguments Array
Callee
New
Extend
Super
Glossary
 
 
Debreuil Digital Works © 2001
 

Summary

DOWNLOAD OO system

Here we will just summarize how to use the Object-Oriented system in Actionscript, without getting into how it works. It is actaully quite simple. We will start with 'recommended usage', and then cover what is mandatory and what is optional. Here is the structure of a typical class:

Sample Usage

// class name and constructor
ClassName = function( arg0, arg1, arg3 )
{
  this.super( arg1, arg2 );
  this.instanceProp0 = arg0;
}
// set class properties (end up in class prototype)
ClassName.prototype.classProperties = function( )
{
  this.prop1 = "hello";
  this.prop2 = "world";
}
// set class methods (ends up in class prototype)
ClassName.prototype.classMethods = function( )
{
  this.method1 = function( ){ ... }
  this.method2 = function( ){ ... }
}
// set inheritance
Object.extends( SuperClassName, ClassName );

Requirements

The first line of every constructor must be this.super( ... ). Any arguments that you wish to set in higher level constructors should be passed upward in the super method.

Setting the inheritance with the extends method must come last, unless you are not using the classProperties and classMethods routines and just setting prototypes manually

Though not required, there are many advantages to defining the prototype using the classProperties and classMethods routines.

Options

Custom methods and properites (Actionscript extentions, debugging tools) can be placed in Object.customMethods.prototype.xxx and automatically be available to all classes and instances (without pollution).

You can choose not to use the classProperties and classMethods routines to set your prototypes. This will make it impossible to (relativly) have prototype properties access prototype methods when being defined, so it tends to push properties onto the instances. If you are ok with this, then you can do as you like (or re-read this section!).

You can pass as many arguments as you like up the chain, but if you pass more than eight, you will have to modify the super method by adding extra arguments.

The super keyword should probably be _super and extends should probably be _extends. These may or may not be reserved words in future versions of Flash... This will probably change very soon, hmm...

 

 

Custom < < Home > > Glossary