Dynamic Class Linkage with __proto__
This is just a proof of concept with no real application yet. Not sure that even qualifies a ‘concept’ or ‘proof’.
This example uses Object.registerClass, __proto__, prototype and is an AS 1.0 approach vs. an AS 2.0 approach. I found some links on this before but never connected the dots. I should also think about how __resolve might play in with this too. This might just be a case of Multiple Inheritance.
I’ve been attaching MovieClips from the library and using an AS 2.0 class with the Linkage Identifier. While this has worked great, this new method allows me to choose whether or not I need to link it in the library vs. dynamic controlling an objects class before AND after attaching it. Although I’m not sure the consequences of that yet.
I’ll post a real example later, but here is the code…
» Permalink » del.icio.us » Digg It!

jgraup said,
February 20, 2007 @ 6:32 pm
ActionScript Object Duplication - var _t = new this.__proto__.constructor(this) ;
http://theolagendijk.wordpress.com/2006/09/04/actionscript-object-duplication/
jgraup said,
February 21, 2007 @ 9:41 am
Xml Dialect for Flash User Interfaces
http://www.simonwacker.com/blog/archives/000105.php
Multiple Inheritance
http://www.simonwacker.com/blog/archives/000007.php
jgraup said,
February 21, 2007 @ 2:56 pm
As Senocular points out, this is going to be an almost 3 year old topic.
How to use Object.registerClass with 2.0 class
http://www.actionscript.org/forums/showthread.php3?t=37103&page=2
jgraup said,
February 25, 2007 @ 12:19 pm
Different ways of inheritance in Flash 5 and Flash MX
http://www.quantumwave.com/flash/inheritance.html
http://www.quantumwave.com/flash/inheritance.html#mx
Demonstration of object inheritance in Flash 5 ActionScript:
http://www.quantumwave.com/flash/inheritanceExample.html
Virtual Movieclip Class (aka MovieClip Inheritance or MovieClip SubClass)
http://www.quantumwave.com/flash/vmc.html
Demonstration of static methods and properties in ActionScript
http://www.quantumwave.com/flash/static.html
jgraup said,
February 25, 2007 @ 12:21 pm
http://timotheegroleau.com/Flash/articles/private_static.htm
Function.prototype.cExtends = function(SuperClass)
{
this.prototype.__proto__ = SuperClass.prototype;
this.prototype.__constructor__ = SuperClass;
ASSetPropFlags(this.prototype, “__constructor__”, 1);
this.__proto__ = SuperClass;
}
SuperTest = function() {};
SuperTest.addStaticProperty(”prop”, 5);
Test = function() {};
Test.prototype = new SuperTest();
or
Test.cExtends(SuperTest);
jgraup said,
February 25, 2007 @ 12:29 pm
Parametrized functions, Static properties and methods and Private properties
http://timotheegroleau.com/Flash/articles/private_static.htm
jgraup said,
March 2, 2007 @ 9:57 pm
__resolve
http://www.createage.com/blog/?p=107
jgraup said,
June 3, 2007 @ 12:36 am
// SET CLASS AFTER ATTACHING
var box = this.attachMovie ( ‘box’, ‘box’, this.getNextHighestDepth() );
setObjectClass ( box, jgButton );
function setObjectClass ( object, Class )
{
// Changes and objects class.
// Because you are only chnaging the class,
// the constructor will never be called.
//
// USAGE:
// setObjectClass ( myObject, myClass );
object.__proto__ = Class.prototype;
}
// SET CLASS BEFORE ATTACHING
registerLinkIDClass ( ‘box’, jgButton );
var box = this.attachMovie ( ‘box’, ‘box’, this.getNextHighestDepth() );
function registerLinkIDClass ( linkageID, Class )
{
// Associates a linkageID with a class.
// When you use attachMovie ( ‘linkageID’, … ),
// the movieClip will be an instance of that class.
//
// USAGE:
// registerLinkIDClass ( myMovieClipLinkageID, myClass );
Object.registerClass( linkageID, Class ); // register class to library linkageID
}