I have a Bullet class that I call every time my shoots a bullet, but I am getting this error: “TypeError: Error #1009: Cannot access a property or method of a null object reference”.
This is a small snippet of code of where I am having trouble with my class:
[AS]
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
public class Bullet {
public var x:Number;
public var y:Number;
public var speed:uint = 5;
public var texture:BitmapData;
public var rec:Rectangle = new Rectangle(0, 0, texture.width, texture.height);
public var point:Point = new Point(0, 0);
public function Bullet(x1:Number, y1:Number, c:uint) {
x = x1;
y = y1;
texture = new BitmapData(5, 5, false, c);
} // end function
}
[/AS]
The problem occurs when I try to pass the BitmapData fillColor value. If I were to create the BitmapData where I first declare the variable “texture” and give it a color, it will work like a charm. However, I want to set the fillColor dynamically because of who is shooting the bullet. ie, heroes bullets are green, enemies are red.
Why am I getting this error and how do I fix it?