# Problem when instanciating a class

**URL:** <https://forum.kirupa.com/t/problem-when-instanciating-a-class/269745>\
**Category:** flash\
**Created:** [September 1, 2008, 1:08am UTC](https://forum.kirupa.com/t/problem-when-instanciating-a-class/269745 "2008-09-01T01:08:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ismael\_92](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@Ismael\_92](https://forum.kirupa.com/u/Ismael_92)\
**Post date:** [September 1, 2008, 1:08am UTC](https://forum.kirupa.com/t/problem-when-instanciating-a-class/269745/1 "2008-09-01T01:08:32Z")

</div>

In the game I’m making, I have a class called _slowBall_, which extends MovieClip.

The class works perfectly because when I put the movieclip on the stage and test the game everything goes fine. But the problem happens when I try to put the movieclip on the stage using actionscript. This is the code I put on the timeline:

_var ball:slowBall = new slowBall();_

And that’s when I get the error _“TypeError: Error # 1009: Unable to access a property or a method of a reference to an object nil.  
At slowBall / EFrame ()”_ (I actually get the error in Spanish, so I translated via Google to put it here).

After some working some time on figuring out what’s wrong with my class, I discovered that it has to do with the following piece of code:

```auto
if (this.hitTestObject(_root.rightPaddle) && xtimer==0) {
slowXSpeed*=-1;
xtimer++;
}

```

(I’ve created the following var before so I can use \_root: _private var \_root:Object=MovieClip(root);_)

The problem is with _\_root.rightPaddle_ (rightPaddle is a movieclip located in the main timeline).  
As I said, I only get this error when I try to create the movieclip using AS, so the class itself is fine.

I need to know how to hittest that class and the movieclip _rightPaddle_ (which is on the main timeline) without using the code I already have…

I have no idea… What can I do?  
Thanks…

PS: I can post the full class if you want to, but I think it’s not necessary.
