# Adding a class constructor for my class gets TypeError

**URL:** https://forum.kirupa.com/t/adding-a-class-constructor-for-my-class-gets-typeerror/228169
**Category:** Uncategorized
**Created:** [June 5, 2007, 8:51pm UTC](https://forum.kirupa.com/t/adding-a-class-constructor-for-my-class-gets-typeerror/228169 "2007-06-05T20:51:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![imadingo](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imadingo](https://forum.kirupa.com/u/imadingo)
#### Post date: [June 5, 2007, 8:51pm UTC](https://forum.kirupa.com/t/adding-a-class-constructor-for-my-class-gets-typeerror/228169/1 "2007-06-05T20:51:24Z")

</div>

I have a class Cannon, which is linked from my library…  
When I don’t have the constructor in, and on the first frame of my timeline I do:

```auto
addChild(new Cannon());

```

It works perfectly.

But, when I add the constructor, even if there is nothing in the constructor, i get this error at compile-time:

```auto

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Cannon$iinit()
    at cannon_fla::MainTimeline/cannon_fla::frame1()

```

Does anyone know whats going on?

This is my shortened code with the constructor:

```auto

package {
    public class Cannon extends MovieClip{
        ...
        public function Cannon(){
           ...
        }
        ...
    }
}

```
