# Making hit tests work with multiple instances of a movieclip

**URL:** <https://forum.kirupa.com/t/making-hit-tests-work-with-multiple-instances-of-a-movieclip/322344>\
**Category:** flash\
**Created:** [May 18, 2011, 2:09pm UTC](https://forum.kirupa.com/t/making-hit-tests-work-with-multiple-instances-of-a-movieclip/322344 "2011-05-18T14:09:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NoobSurfer](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@NoobSurfer](https://forum.kirupa.com/u/NoobSurfer)\
**Post date:** [May 18, 2011, 2:09pm UTC](https://forum.kirupa.com/t/making-hit-tests-work-with-multiple-instances-of-a-movieclip/322344/1 "2011-05-18T14:09:23Z")

</div>

I seem to have a bit of a problem with getting the collision detection working in harmony with the rest of my code. Basically i have an array that creates multiple instances of a movieclip named mcPlatformStandard with the following piece of code…

```auto
//this variable holds all of the platforms
var platformHolder:MovieClip = new MovieClip();
//adds the platform to stage
addChild(platformHolder);
function createLvlOne():void{
    //now we must create the level
    for(var i:int = 0;i<xStandardOneArray.length;i++){
        //making a new standard platform
        var platformStandard:mcPlatformStandard = new mcPlatformStandard();
        //adding platformStandard to stage
        platformHolder.addChild(platformStandard);
        
        platformStandard.x=levelOneArray[0][0]*;
        platformStandard.y=levelOneArray[0][1]*;
    }
}

//running the createlvl funciton
createLvlOne();

```

This seems to work well enough. When i try and when i link the following code (which contains the hit test) with the main file, however, it just plain doesn’t work…

```auto
package{
    import flash.display.MovieClip;
    import flash.events.*;
    public class mcPlatformStandard extends MovieClip {
 
        var _root:Object;//this will symbolize the main timeline
 
        public function mcPlatformStandard() {
            addEventListener(Event.ADDED, standardJump);
        }
        private function standardJump(e:Event):void{
            if(this.hitTestObject(_root.mcMain)){//if this touches the main character
                _root.mainJumping = true;//make him jump
                _root.jumpSpeed = _root.jumpSpeedLimit*-1;//reset the jumpSpeed
            }
        }
    }
}

```

In the output tab it says

“TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at mcPlatformStandard/standardJump()  
at flash.display::DisplayObjectContainer/addChild()  
at MyGame\_fla::MainTimeline/createLvlOne()  
at MyGame\_fla::MainTimeline/frame2()”

Please someone tell me what im missing. Im not that experienced with classes but i will try any advice im given.

Thanks in advance (and sorry for bad terminology)
