Hi all, Got a bit of a tricky problem here that I'm banging my head against...
If you assume I have some function that returns a Class object - for example: getAssetClass(id:String):Class This returns a Class object which, at some future time, will be called with new SomeClass() to construct an instance of an object. Let's assume that the body of the function looks something like this: function getAssetClass(id:String):Class { return GenericAssetClass; } However, the actual behaviour I need changes depending on the value of 'id'. Effectively what I want to happen is for the returned class to be parameterised in some way - so that when new SomeClass() is called it evaluates to new GenericAssetClass(id). In AS2, this was possible because constructors were just functions. I could happily say: function getAssetClass(id:String):Function { return function():Object {return new GenericAssetClass(id);} } However, in AS3 this won't work, as Class is quite a different thing from Function. Changing GenericAssetClass.prototype.constructor doesn't help, as it's static and applies to all instances of GenericAssetClass. Doing something like this: function getAssetClass(id:String):Class { GenericAssetClass.id=id; return GenericAssetClass; } class GenericAssetClass { public static id:String; public function GenericAssetClass() { // Do something that depends on 'id' } } won't help either, because as soon as you change the static GenericAssetClass.id, that change applies to all the constructors you've handed out. I could do something like this: function getAssetClass(id:String):Class { if (id=="id1") return GenericAssetClass1; else if (id=="id2") return GenericAssetClass2; // etc. as required } but the trouble is that there is only one, parameterised GenericAssetClass and I can't define all the options up front - it truly is dynamic. *sigh* I've a feeling this ought to be possible, I just can't for the life of me think how. Is there any way I can hook into the new Class() call somewhere? Or uniquely identify each reference to GenericAssetClass that I've handed out, so that I can use a lookup table during the construction phase? Thanks in advance, Ian