I’ve struck a rather odd problem in my flash game. I get a “Error #1009: Cannot access a property or method of a null object reference.” error in the following block of code:
public function createHero()
{
hero = new Object();
hero.mc = gamelevel.hero;
hero.dx = 0.0;
hero.dy = 0.0;
hero.inAir = false;
hero.direction = 1;
hero.animstate = "stand";
hero.walkAnimation = new Array(2, 3, 4, 5, 6, 7, 8);
hero.animstep = 2;
hero.jump = false;
hero.moveLeft = false;
hero.moveRight = false;
hero.jumpSpeed = 0.8;
hero.walkSpeed = 0.15;
hero.width = 64.0;
hero.height = 96.0;
hero.startX = hero.mc.x;
hero.startY = hero.mc.y;
hero.profile = "technology";
hero.ability = "robot";
hero.activePhotoFrame = false;
}
Using the debugger I’ve narrowed the error down to “hero.mc = gamelevel.hero;”. I tried figuring out if hero.mc or gamelevel.hero was the culprit by using a test object.
testObject = gamelevel; //worked perfectly fine
testObject = gamelevel.hero; //gave the error
testObject.mc = gamelevel; //also gave the error
testObject.mc = gamelevel.hero; //gave the same error as well
I don’t understand what the problem is.
For clarification “gamelevel” is the instance name of a movieclip containing another movieclip with the instance name “hero”
The problem isn’t limited to the hero object. If I comment it out I get the error with any other object assigning gamelevel.something to a mc property.
What makes it stranger is that this worked perfectly fine before.
If any other information is required, please don’t hesitate to ask.
Turned out one of the images was corrupted…