# Getting an instance's main class

**URL:** https://forum.kirupa.com/t/getting-an-instances-main-class/292984
**Category:** flash
**Created:** [July 21, 2009, 6:01pm UTC](https://forum.kirupa.com/t/getting-an-instances-main-class/292984 "2009-07-21T18:01:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![IQAndreas](https://avatars.discourse-cdn.com/v4/letter/i/f08c70/32.png) [@IQAndreas](https://forum.kirupa.com/u/IQAndreas)
#### Post date: [July 21, 2009, 6:01pm UTC](https://forum.kirupa.com/t/getting-an-instances-main-class/292984/1 "2009-07-21T18:01:24Z")

</div>

Say I have a variable that contains an instance of a class. Is there any way to return a “Class” object based on what type that variable is?

I wish there was something like this:

```auto
var button:SimpleButton = new SimpleButton();
this.addChild(duplicate(button));

function duplicate(target:Object):Object
        var mainClass:Class = target.baseClass; //Yes, I know the "baseClass" function doesn't exist. This is what I want.
        var cloneObj:Button = new MainClass();
        return cloneObj;
}

```

I am able to extract the class name in text format, and even all items that it extends and interfaces, yet I cannot find any way to create a class based on

I did find the function “getDefinitionByName()” and “getClassByAlias()”, but if I understand correctly, you have to first register those definitions.

Also, is it possible to extract usable Classes (not just display objects) out of externally loaded SWFs?
