Created
April 29, 2010 18:19
-
-
Save robertpenner/383991 to your computer and use it in GitHub Desktop.
Inheritance chain hacking in AS2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Makes an object inherit from a class. | |
* Modifies the inheritance chain and calls the class constructor. | |
* Commonly used to make a movie clip such as the root timeline | |
* inherit from a custom class, e.g. | |
* // on main timeline | |
* applyClassToInstance(MyDocumentClass, this); | |
* Works for AVM1 only, i.e. AS1 and AS2. | |
* @param theClass | |
* @param theInstance | |
* @param constructorArgs An optional Array of parameters for the class constructor. | |
*/ | |
function applyClassToInstance(theClass:Function, theInstance:Object, constructorArgs:Array):Void | |
{ | |
theInstance.__proto__ = theClass.prototype; | |
theInstance.__constructor__ = theClass; | |
// run the constructor | |
theClass.apply(theInstance, constructorArgs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment