Copy link to clipboard
Copied
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at project_fla::MainTimeline/moveChar()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at project_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at project_fla::MainTimeline/fl_ClickToGoToScene()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Enemy/eFrame()
Can somebody help me to solve this problem?my game can launch but the error still appear. I'm newbie on adobe animate...
stop();
//these booleans will check which keys are down
var leftDown:Boolean = false;
var upDown:Boolean = false;
var rightDown:Boolean = false;
var downDown:Boolean = false;
//how fast the character will be able to go
var mainSpeed:int = 5;
//how much time before allowed to shoot again
var cTime:int = 0;
//the time it has to reach in order to be allowed to shoot (in frames)
var cLimit:int = 12;
//whether or not the user is allowed to shoot
var shootAllow:Boolean = true;
//how much time before another enemy is made
var enemyTime:int = 0;
//how much time needed to make an enemy
//it should be more than the shooting rate
//or else killing all of the enemies would
//be impossible 😮
var enemyLimit:int = 16;
//the player's score
var score:int = 0;
//this movieclip will hold all of the bullets
var bulletContainer:MovieClip = new MovieClip();
addChild(bulletContainer);
//whether or not the game is over
var gameOver:Boolean = false;
//adding a listener to spaceship_1 that will move the character
spaceship_1.addEventListener(Event.ENTER_FRAME, moveChar);
function moveChar(event:Event):void{
//checking if the key booleans are true then moving
//the character based on the keys
if(leftDown){
spaceship_1.x -= mainSpeed;
}
if(upDown){
spaceship_1.y -= mainSpeed;
}
if(rightDown){
spaceship_1.x += mainSpeed;
}
if(downDown){
spaceship_1.y += mainSpeed;
}
//keeping the main character within bounds
if(spaceship_1.x <= 0){
spaceship_1.x += mainSpeed;
}
if(spaceship_1.y <= 0){
spaceship_1.y += mainSpeed;
}
if(spaceship_1.x >= stage.stageWidth - spaceship_1.width){
spaceship_1.x -= mainSpeed;
}
if(spaceship_1.y >= stage.stageHeight - spaceship_1.height){
spaceship_1.y -= mainSpeed;
}
//Incrementing the cTime
//checking if cTime has reached the limit yet
if(cTime < cLimit){
cTime ++;
} else {
//if it has, then allow the user to shoot
shootAllow = true;
//and reset cTime
cTime = 0;
}
//adding enemies to stage
if(enemyTime < enemyLimit){
//if time hasn't reached the limit, then just increment
enemyTime ++;
} else {
//defining a variable which will hold the new enemy
var newEnemy = new Enemy();
//making the enemy offstage when it is created
newEnemy.y = -1 * newEnemy.height;
//making the enemy's x coordinates random
//the "int" function will act the same as Math.floor but a bit faster
newEnemy.x = int(Math.random()*(stage.stageWidth - newEnemy.width));
//then add the enemy to stage
addChild(newEnemy);
//and reset the enemyTime
enemyTime = 0;
}
//updating the score text
txtScore.text = 'Score: '+score;
}
//this listener will listen for down keystrokes
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
function checkKeysDown(event:KeyboardEvent):void{
//making the booleans true based on the keycode
//WASD Keys or arrow keys
if(event.keyCode == 37 || event.keyCode == 65){
leftDown = true;
}
if(event.keyCode == 38 || event.keyCode == 87){
upDown = true;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightDown = true;
}
if(event.keyCode == 40 || event.keyCode == 83){
downDown = true;
}
//checking if the space bar is pressed and shooting is allowed
if(event.keyCode == 32 && shootAllow){
//making it so the user can't shoot for a bit
shootAllow = false;
//declaring a variable to be a new Bullet
var newBullet:Bullet = new Bullet();
//changing the bullet's coordinates
newBullet.x = spaceship_1.x + spaceship_1.width/2 - newBullet.width/2;
newBullet.y = spaceship_1.y;
//then we add the bullet to stage
bulletContainer.addChild(newBullet);
}
}
//this listener will listen for keys being released
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
function checkKeysUp(event:KeyboardEvent):void{
//making the booleans false based on the keycode
if(event.keyCode == 37 || event.keyCode == 65){
leftDown = false;
}
if(event.keyCode == 38 || event.keyCode == 87){
upDown = false;
}
if(event.keyCode == 39 || event.keyCode == 68){
rightDown = false;
}
if(event.keyCode == 40 || event.keyCode == 83){
downDown = false;
}
}
/* Click to Go to Previous Scene and Play
Clicking on the specified symbol instance moves the playhead to the previous scene in the timeline and continues playback in that scene.
*/
back_btn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousScene_1);
function fl_ClickToGoToPreviousScene_1(event:MouseEvent):void
{
MovieClip(this.root).prevScene();
}
Copy link to clipboard
Copied
click file>swf>permit debugging and retest.
the line number of the non-existant object will be in the error message. if that doesn't make the solution obvious to you, what line of code contains the error?
Copy link to clipboard
Copied
i dint found swf on file
Copy link to clipboard
Copied
that should be files>publish settings > swf > permit debugging