Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

super.super.super.as

Name: super.super.super... [MX]
Author: senocular: www.senocular.com
Date: 1899-12-31T00:21:24.200
Documentation:
SUPER extension: (super extension as in it extends
the super object, not that its this grandly amazing
extension... well unless you want to think that ;)
- Allows to chain super objects to gain access to super
constructors and/or methods by chaining super objects together
Note: this itself is not a class but rather a method of
extending super which is used in class structuring.

- Super alone calls a class's super constructor i.e. super();  It can also be used with a
method to call that class's super constructor's proto methods; i.e. super.method();
However, super doesn't allow you to access a superclass's superclass or its methods (directly)
...until now.

super.super(); <-- superclass's superclass constructor
super.super.method(); <-- superclass's superclass method 
super.super.super(); <-- superclass's superclass superclass constructor
super.super.super.method(); <-- superclass's superclass superclass method 
... etc.
(see example in code definition)

Note:
- be sure not to have any super methods or properties in your class or it will break the
super.super chain (your super will be used instead of the Object.prototype.super) By this
I mean no method or property named "super".


- havent really used it too terribly extensively.  Im sure there are ways to break it :)
but its doing what it needs to for me now so I thought Id throw it out there.

Example:
// setup inheritance chain (not exactly most intuitive
// but makes sense in their order aspect)
// small isa medium isa large isa supersize

SuperSize = function(){
	trace("Super constructor");
}
SuperSize.prototype.meth = function(){
	trace("SUPER! SUPER! SUPER!");
}
Large = function(){
	trace("Large constructor");
}
Large.prototype = new SuperSize();
Large.prototype.meth = function(){
	trace("Large meth");
}
Medium = function(){
	trace("Medium constructor");
}
Medium.prototype = new Large();
Medium.prototype.meth = function(){
	trace("Medium meth");
}
Small = function(){}
Small.prototype = new Medium();
Small.prototype.callAll = function(){
	trace("\nCall All:");
	super(); // should call Medium function
	super.meth(); // should call Medium.prototype.meth
	super.super(); // should call Large function
	super.super.meth(); // should call Large.prototype.meth
	super.super.super(); // should call SuperSize function
	super.super.super.meth(); // should call SuperSize.prototype.meth
}

tinyInstance = new Small();
tinyInstance.callAll();

// output
Super constructor
Large constructor
Medium constructor

Call All:
Medium constructor
Medium meth
Large constructor
Large meth
Super constructor
SUPER! SUPER! SUPER!

1
2
3
4
5
6
7
8
9
10
11
12
13
Object.prototype.addProperty("super",
	function(){
		if (this.$isInSuperChain){
			var p = new Object(this.__constructor__);
			p.__proto__ = this.__proto__.__proto__;
		}else{
			var p = new Object(this.__proto__.__proto__.__constructor__);
			p.__proto__ = this.__proto__.__proto__.__proto__;
		}
		p.$isInSuperChain = true;
		return p;
	},null);
ASSetPropFlags(Object.prototype,"super",7);