Dynamic Class Instantiation

Alright, I solved this problem for AS2 and AS3, but it’s not as elegant as I’d like.


import flash.utils.getDefinitionByName;
var className:String = "com.cfms.Navigation";
var classReference:Class = getDefinitionByName(className) as Class;
var classInstance:Object = new classReference();

This all works well and gravy if I’ve already defined the Navigation class once before, as such:


import com.cfms.Navigation;
var nav = new Navigation();
nav = null;

But I was wondering if there was any way possible to skip that last step, instead of having to add in all the manual instances? I understand this is so that Flash will compile the classes into the SWF document, but is there a more elegant way to do this?