I'm unsuccessfully attempting to instantiate a reference of a class that is passed as a parameter to another class.

in this example there are 3 classes: **MainClass, Canvas, MyCircle**

from the MainClass i am creating an instance of Canvas, which is passed a class reference of MyCircle as i want to create instances of MyCircle from within Canvas. however, the MyCircle constructor contains required parameters that are created from within Canvas.

how can i pass and instantiate a class reference with required parameters?

**MyCircle:**

```
package
{
    //Imports
    import flash.display.Shape;

    //Class
    public class MyCircle extends Shape
    {
        //Constructor
        public function MyCircle(color:uint, radius:uint)
        {
            graphics.beginFill(color, 1.0);
            graphics.drawCircle(0, 0, radius);
            graphics.endFill();
        }
    }
}

```

**Canvas:**

```
package
{
    //Imports
    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.utils.getDefinitionByName;

    //Class
    public class Canvas extends Sprite
    {
        //Constructor
        public function Canvas(circleClassReference:String, amount:uint)
        {
            var CircleReference:Class = getDefinitionByName(circleClassReference) as Class;

            for (var i:uint = 0; i < amount; i++)
            {
                var randomColor:uint = Math.random() * 0xFFFFFF;
                var randomRadius:uint = Math.random() * 100 + 50;

                var circleInstance:DisplayObject = new CircleReference(randomColor, randomRadius);
                circleInstance.y = i * randomRadius;

                addChild(circleInstance);   
            }
        }
    }   
}

```

**MainClass:**

```
package
{
    //Imports
    import flash.display.Sprite;

    //Class
    public class MainClass extends Sprite
    {
        //Constructor
        public function MainClass()
        {
            var myCanvas:Canvas = new Canvas("MyCircle", 10);
            addChild(myCanvas)
        }
    }
} 

```

---

**[EDIT]**

---

it seems that passing the actual Class instead of the name of the class avoids the need for the dirty fix that is mentioned below.

**MainClass Constructor**

```
public function MainClass()
{   
    var myCanvas:Canvas = new Canvas(MyCircle, 10);
    addChild(myCanvas)
}

```

**Canvas Constructor**

```
public function Canvas(circleClassReference:Class, amount:uint)
{
    var CircleReference:Class = circleClassReference;

    for (var i:uint = 0; i < amount; i++)
    {
        var randomColor:uint = Math.random() * 0xFFFFFF;
        var randomRadius:uint = Math.random() * 100 + 50;

        var circleInstance:DisplayObject = new CircleReference(randomColor, randomRadius);
        circleInstance.y = i * randomRadius;

        addChild(circleInstance);   
    }
}

```