Is it possible to cast a variable as a type dynamically, where the type would be a variable of type Class
?
Consider the following (invalid):
var myClass:Class = MyClass;
var myInstance:myClass = new myClass();
For context: I'm working in Flex (4) to create a modal manager that will control various aspects of creating modals (via PopUpManager
) and I'd like to keep it as minimal as possible. Components would be passed through the same functions, and rather than allowing any type of variable to be cast, eg:
var myInstance:* = new myClass();
I'd rather keep it as explicit as possible. Granted AFAIK there is no -real- advantage to doing this, as there are checks to make sure that the argument is of type Class
before assigning - it's more of a POC than anything.
Any thoughts are welcome.
Edit: I suppose I could do the following:
var myClass:Class = MyClass;
var myInstance:* = new myClass() as myClass;
but I'm not sure if that's the best way to go about it.