# Error #1009

**URL:** <https://forum.kirupa.com/t/error-1009/316107>\
**Category:** Uncategorized\
**Created:** [November 12, 2010, 12:55pm UTC](https://forum.kirupa.com/t/error-1009/316107 "2010-11-12T12:55:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WEich1213](https://avatars.discourse-cdn.com/v4/letter/w/ecb155/32.png) [@WEich1213](https://forum.kirupa.com/u/WEich1213)\
**Post date:** [November 12, 2010, 12:55pm UTC](https://forum.kirupa.com/t/error-1009/316107/1 "2010-11-12T12:55:48Z")

</div>

I’m getting this error when I try to use a bitmap collision test:

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at PlayerGroundCollisions/frameEvents()[/Users/Bill/Desktop/Lunar\_Madnes s/PlayerGroundCollisions.as:41]  
at Lunar\_Madness/onEnterFrame()[/Users/Bill/Desktop/GAME STUFF/Lunar\_Madness/Lunar\_Madness.as:61]

Here’s the code,

PlayerGroundCollisions Class:

package {  
import flash.display.MovieClip;  
import flash.events.Event;  
import flash.display.Bitmap;  
import flash.display.BitmapData;  
import flash.geom.Point;

public class PlayerGroundCollisions extends MovieClip  
{  
private var groundObjects:Array;  
static var \_player:Bitmap;  
static var \_foreground:Bitmap;  
public var \_collisionSide:String;

public function PlayerGroundCollisions()  
{  
addEventListener(Event.ADDED\_TO\_STAGE, onAddedToStage);  
}  
private function onAddedToStage(event:Event):void  
{

//Initialize properties  
\_player = PlayerShip.Player;  
\_foreground = Lunar\_Madness.Foreground;  
//Add event listenters

addEventListener(Event.REMOVED\_FROM\_STAGE, onRemovedFromStage);  
}  
private function onRemovedFromStage(event:Event):void  
{

removeEventListener(Event.ADDED\_TO\_STAGE, onAddedToStage);  
removeEventListener(Event.REMOVED\_FROM\_STAGE, onRemovedFromStage)  
}  
public function frameEvents():void  
{//Directives…  
//var \_foreground = MovieClip(parent).foreground;  
var loopCounter:int = 0;  
while (loopCounter++ != 10)  
{  
if(\_player.bitmapData.hitTest(new Point(\_player.x, \_player.y), 255, \_foreground, new Point (\_foreground.x, \_foreground.y), 255)) ---------\>THIS IS LINE 41 FROM ABOVE  
{

//A collision was found.  
//next teh code creates “collision boxes” on all  
// four sides of the lander to  
// find out on which side the collision is occurring

//Switch off gravity  
PlayerShip.gravity = 0;

//1. Check for a collision on the bottom  
if(\_player.bitmapData.hitTest(new Point(\_player.x, \_player.y + 10), 255, \_foreground, new Point(\_foreground.x, \_foreground.y), 255))  
{  
//Move teh lander out of the collision  
PlayerShip.PlayerY = -1;  
PlayerShip.VY = 0;  
\_collisionSide = “bottom”;  
}  
//2. Check for a collision on the top  
else if(\_player.bitmapData.hitTest(new Point(\_player.x, \_player.y - 10), 255, \_foreground, new Point(\_foreground.x, \_foreground.y), 255))  
{  
//Move teh lander out of the collision  
PlayerShip.PlayerY = 1;  
PlayerShip.VY = 0;  
\_collisionSide = “top”;  
}

//3. Check for a collision on the riht  
else if(\_player.bitmapData.hitTest(new Point(\_player.x + 10, \_player.y), 255, \_foreground, new Point(\_foreground.x, \_foreground.y), 255))  
{  
//Move teh lander out of the collision  
PlayerShip.PlayerX = -1;  
PlayerShip.VX = 0;  
\_collisionSide = “right”;  
}  
//4. Check for a collision on the left  
else if(\_player.bitmapData.hitTest(new Point(\_player.x - 10, \_player.y + 10), 255, \_foreground, new Point(\_foreground.x, \_foreground.y), 255))  
{  
//Move teh lander out of the collision  
PlayerShip.PlayerX = +1;  
PlayerShip.VX = 0;  
\_collisionSide = “left”;  
}  
else{  
break;  
}  
}  
//Switch gravity back on if there is no ground below the lander.  
//Adding "+1+ to the lander;s y position in hte collision  
//test is the key to making this work  
if(!\_player.bitmapData.hitTest(new Point(\_player.x, \_player.y), 255, \_foreground, new Point(\_foreground.x, \_foreground.y), 255))  
{  
PlayerShip.gravity = .015;

}  
}

}

}  
}

LunarMadness Class:

package {  
import flash.display.MovieClip;  
import flash.events.Event;  
import flash.display.Bitmap;  
import flash.display.BitmapData;

public class Lunar\_Madness extends MovieClip  
{

private var \_playerShip:PlayerShip;  
private var \_playerMissiles:PlayerMissiles;  
public static var foreground:Bitmap;  
private var \_shipGroundCollide:PlayerGroundCollisions;

public var imageBitmapData:BitmapData;  
public var foreground:Bitmap;

public function Lunar\_Madness()  
{

\_playerShip = new PlayerShip();  
\_playerMissiles = new PlayerMissiles();  
\_shipGroundCollide = new PlayerGroundCollisions();

addEventListener(Event.ADDED\_TO\_STAGE,onAddedToStage);  
}  
private function onAddedToStage(event:Event):void  
{

//Initialize properties  
imageBitmapData = new Fg(1437, 376);

foreground = new Bitmap(imageBitmapData);  
foreground.x = -26;  
foreground.y = 216;

addChild(foreground);

addChild(\_playerShip);  
addChild(\_playerMissiles);  
addChild(\_shipGroundCollide);  
//Add event listenters

addEventListener(Event.ENTER\_FRAME, onEnterFrame);  
addEventListener(Event.REMOVED\_FROM\_STAGE, onRemovedFromStage);  
}  
private function onRemovedFromStage(event:Event):void  
{  
removeEventListener(Event.ENTER\_FRAME, onEnterFrame);  
removeEventListener(Event.ADDED\_TO\_STAGE, onAddedToStage);  
removeEventListener(Event.REMOVED\_FROM\_STAGE, onRemovedFromStage)  
}  
private function onEnterFrame(event:Event):void  
{//Directives…

\_playerShip.frameEvents(); - ----------------\>LINE 61 FROM ABOVE

\_playerMissiles.frameEvents();  
\_shipGroundCollide.frameEvents();  
}

public static function get Foreground():Bitmap  
{  
return foreground;  
}

}  
}

CAN ANYONE CLUE ME IN AS TO WHAT THE PROBLEM IS?
