# Instantiate class

**URL:** https://forum.kirupa.com/t/instantiate-class/252248
**Category:** Uncategorized
**Created:** [February 18, 2008, 1:01pm UTC](https://forum.kirupa.com/t/instantiate-class/252248 "2008-02-18T13:01:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jbuda](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jbuda/32/3723_2.png) [@jbuda](https://forum.kirupa.com/u/jbuda)
#### Post date: [February 18, 2008, 1:01pm UTC](https://forum.kirupa.com/t/instantiate-class/252248/1 "2008-02-18T13:01:51Z")

</div>

Hi

Im trying to instantiate a class called Favourites\_panel1 from FavouritesPanel.  
Im passing an argument into FavouritesPanel to call te relevant class for which style of panel to create.

Im getting this error when attempting it…

```
Quote:
 	 		 			 				TypeError: Error #1007: Instantiation attempted on a non-constructor. 			 		 	 	 

```

The code for each class is below…

FavouritesPanel.as

```
Code:
package {

import flash.display.Sprite;	
import favourites_classes.*;

public class FavouritesPanel extends Sprite {		
	private var _type:String;
	
	function FavouritesPanel($type:String = 'Favourites_panel1') { 
		// different type for different sections
		_type = $type;
		init();
	}
	
	private function init():void {
		var targetClass:String = String(_type);
                    var duplicate:* = new [targetClass]();
       }
}

```

}  
And this is the class tat extends the above, and that want instantiated when the above tries to…

Favourites\_panel1.as

```
Code:
package favourites_classes {

public class Favourites_panel1 extends FavouritesPanel {
	
	function Favourites_panel1() { 
		trace(' i have been ccreated');
	}
		
}

```

}  
ANy help is greatly appreciated!!
