I have been working on a game in flash as3, which worked perfectly up until I rearranged all of the variables up at the top to make it easier to read. Now the debugger is throwing an Error 1009 for many of the variables during run time, despite their definitions not having changed.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main_fla::MainTimeline/Update()[Main_fla.MainTimeline::frame3:201]
The error points me to:
if (S) {
legRot = 180;
}
Despite that fact that both S and legRot are defined as;
var legRot:Number = 0;
and
var S:Boolean = false;
with the rest of the variables at the top f the actions on the frame.
Any help is appreciated, Thank You.
Edit
Here are my variable definitions ;
//Numbers
var currentAmmo = 1;
var xVel = 0;
var yVel = 0;
var xCollision = 0;
var yCollision = 0;
var enemySpeed = 4;
var ExplodeOnce = 0;
var EnemyWalking = 0;
var legRot = 0;
var dropxVel: Number = 0;
var dropyVel: Number = 0;
var E = 0;
//Booleans
var A:Boolean = false;
var W:Boolean = false;
var S:Boolean = false;
var D:Boolean = false;
var SHIFT:Boolean = false;
var Q:Boolean = false;
var dead = false;
And here is where the error is occuring;
if (W) {
legRot = 0;
}
if (A) {
legRot = -90;
}
if (S) {
legRot = 180;
}
if (D) {
legRot = 90;
}
if (A && W) {
legRot = -45
};
if (W && D) {
legRot = 45
};
if (D && S) {
legRot = 115
};
if (S && A) {
legRot = -115
};
if (!dead){
player.TopBody.rotation = Math.atan2(mouseY - player.y, mouseX - player.x) * 180 / Math.PI + 90;
if (!W && !A && !S && !D) {
player.BottomLegs.gotoAndStop(1);
player.BottomLegs.rotation = Math.atan2(mouseY - player.y, mouseX - player.x) * 180 / Math.PI + 90;
} else {
player.BottomLegs.play();
player.BottomLegs.rotation += (legRot - player.BottomLegs.rotation) / 4;
}
}
Update()function ? - akmozo