Hello, I am very new to flashpunk and need some help. I am trying to access the x coordinates of my Player entity from my enemy entity so that it will be able to follow the player. But when I do as the “Accessing Entities” ( Accessing Entities ) tutorial, I get this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference. at entities::Enemy_1() at GameWorld/loadMap() at GameWorld() at Main()
Anyone know how to fix this issue? Here is the part of the code that creates the error:
In the enemy class
var player:Player = world.getInstance(“player”) as Player;
and in the update() function of the enemy
if (player){ if (player.x> x) { if (_xspeed < _MAXmovespeed && (_xspeed + _moveAccel) < _MAXmovespeed ) { _xspeed += _moveAccel; } else { _xspeed = _MAXmovespeed; } }
if (player.x < x)
{
if (Math.abs(_xspeed) < _MAXmovespeed && (Math.abs(_xspeed) + _moveAccel) < _MAXmovespeed )
{
_xspeed -= _moveAccel;
}
else
{
_xspeed = -_MAXmovespeed;
}
}
}