Switching Between Two Classes

Hi,

I have this situation where depending on a var, I’d like to be able to choose between two different classes, and then construct objects out of whatever Class I’ve assigned. But I cant seem to get it going.

How do you go about doing this?


var ClassSwitch:Class
			if(menuOrientation=="horizontal"){
				ClassSwitch = getDefinitionByName("NpAccordionPane") as Class;
			}else{
				ClassSwitch =  getDefinitionByName("NpAccordionPaneH") as Class;
			}
var menuItem:ClassSwitch = new ClassSwitch(loadedContent, counter, titleText, action)
//do stuff

Edit:
Got it going like this;


var ClassSwitch:Class
if(menuOrientation=="horizontal"){
				ClassSwitch = NpAccordionPane
			}else{
				ClassSwitch = NpAccordionPaneH
			}
			var menuItem:Object = new ClassSwitch(loadedContent, counter, titleText, action);

This approach means I have to cast the addChild for this class as a DisplayObject.

Not sure if thats the best approach?