PDA

View Full Version : Dynamic Type Casting - Is it possible???



barliesque
January 14th, 2008, 03:05 AM
Is there a way to dynamically typecast a new instance? Maybe something like the following...?



var myClass:String = "blah";
var inst = new[myClass]();


I've invented the above syntax--though I'd be delighted if it turned out to work! For clarity, I would hope for something like the above code to be synonymous with the following:



var inst:blah = new blah();


...So is it possible to dynamically specify a class name when creating a new instance?

barliesque
January 14th, 2008, 03:18 AM
Ah ha! Okay, not to answer my own question--In fact, I got a speedy reply on another forum. So here's how it is indeed possible to dynamically specify a class name when creating a new instance...



var blahClass:Class = getDefinitionByName("blah") as Class;
var inst:Object = new blahClass();


Actually, I think I prefer this to my own made-up syntax.