# Switching Between Two Classes

**URL:** https://forum.kirupa.com/t/switching-between-two-classes/266742
**Category:** flash
**Created:** [July 23, 2008, 11:11pm UTC](https://forum.kirupa.com/t/switching-between-two-classes/266742 "2008-07-23T23:11:29Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dail](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dail](https://forum.kirupa.com/u/dail)
#### Post date: [July 23, 2008, 11:11pm UTC](https://forum.kirupa.com/t/switching-between-two-classes/266742/1 "2008-07-23T23:11:29Z")

</div>

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?

```auto

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;

```auto

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?
