Copy link to clipboard
Copied
When I combine the storytelling part(storytelling that run frame by frame) with platform game, this error appear:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display:: DisplayObject/_hitTest()
at flash.display:: DisplayObject/hitTestObject()
at SaveMyBaby4_fla::Background_27/frame1()
at flash.display::MovieClip/gotoAndPlay()
at SaveMyBaby4_fla::Mainmenu_20/clickStart()
How can i solve it? As i use this coding:
var leftDown:Boolean = false;
var rightDown:Boolean = false;
var upDown:Boolean = false;
var downDown:Boolean = false;
var leftBumping:Boolean = false;
var rightBumping:Boolean = false;
var upBumping:Boolean = false;
var downBumping:Boolean = false;
var leftBumpPoint:Point = new Point(0, 0);
var rightBumpPoint:Point = new Point(0, 0);
var upBumpPoint:Point = new Point(0, 0);
var downBumpPoint:Point = new Point(0, 0);
var scrollX:Number = 500;
var scrollY:Number = 0;
var xSpeed:Number = 0;
var ySpeed:Number = 0;
var speedConstant:Number = 2;
var frictionConstant:Number = 0.9;
var gravityConstant:Number = 1.5;
var jumpConstant:Number = -35;
var maxSpeedConstant:Number = 18;
var doubleJumpReady:Boolean = false;
var upReleasedInAir:Boolean = false;
var door:Boolean = false;
var currentLevel:int = 1;
var animationState:String="rest";
function loop(e:Event):void{
if(back.block.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
//trace("leftBumping");
leftBumping = true;
} else {
leftBumping = false;
}
if(back.block.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
//trace("rightBumping");
rightBumping = true;
} else {
rightBumping = false;
}
if(back.block.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
//trace("upBumping");
upBumping = true;
} else {
upBumping = false;
}
if(back.block.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
//trace("downBumping");
downBumping = true;
} else {
downBumping = false;
}
}
if(leftDown){
xSpeed -= speedConstant;
player.scaleX = -1;
} else if(rightDown){
xSpeed += speedConstant;
player.scaleX = 1;
}
/*if(upPressed){
ySpeed -= speedConstant;
} else if(downPressed){
ySpeed += speedConstant;
}*/
if(leftBumping){
if(xSpeed < 0){
xSpeed *= -0.5;
}
}
if(rightBumping){
if(xSpeed > 0){
xSpeed *= -0.5;
}
}
if(upBumping){
if(ySpeed < 0){
ySpeed *= -0.5;
}
}
if(downBumping){ //if we are touching the floor
if(ySpeed > 0){
ySpeed = 0; //set the y speed to zero
}
if(upDown){ //and if the up arrow is pressed
ySpeed = jumpConstant; //set the y speed to the jump constant
}
//DOUBLE JUMP
if(upReleasedInAir == true){
upReleasedInAir = false;
}
if(doubleJumpReady == false){
doubleJumpReady = true;
}
} else { //if we are not touching the floor
ySpeed += gravityConstant; //accelerate downwards
//DOUBLE JUMP
if(upDown == false && upReleasedInAir == false){
upReleasedInAir = true;
//trace("upReleasedInAir");
}
if(doubleJumpReady && upReleasedInAir){
if(upDown){ //and if the up arrow is pressed
//trace("doubleJump!");
doubleJumpReady = false;
ySpeed = jumpConstant; //set the y speed to the jump constant
}
}
}
if(door == false)
{
if(player.hitTestObject(back.door))
{
door = true;
}
}
if(xSpeed > maxSpeedConstant){ //moving right
xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){ //moving left
xSpeed = (maxSpeedConstant * -1);
}
xSpeed *= frictionConstant;
ySpeed *= frictionConstant;
if(Math.abs(xSpeed) < 0.5){
xSpeed = 0;
}
scrollX -= xSpeed;
scrollY -= ySpeed;
back.x = scrollX;
back.y = scrollY;
sky.x = scrollX * 0.2;
sky.y = scrollY * 0.2;
if((leftDown||rightDown||xSpeed>speedConstant||xSp eed<speedConstant*-1)&&downBumping){
animationState="playerrun";
}
else if(downBumping){
animationState="rest";
}
else{
animationState="jump";
}
if(player.currentLable!=animationState){
player.gotoAndStop(animationState);
}
function nextLevel():void{
currentLevel++;
{
gotoAndPlay(4, "Scene 1");
door = false;
}
function keyDownHandler(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.LEFT)
{
leftDown = true;
}
else if(e.keyCode == Keyboard.RIGHT)
{
rightDown = true;
}
else if(e.keyCode == Keyboard.UP)
{
upDown = true;
}
else if(e.keyCode == Keyboard.DOWN)
{
downDown= true;
if(player.hitTestObject(back.door))
{
//proceed to the next level if the player is touching an open door
door = true;
gotoAndPlay(5, "Scene 1");
}
}
}
function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
leftDown = false;
} else if(e.keyCode == Keyboard.RIGHT){
rightDown = false;
} else if(e.keyCode == Keyboard.UP){
upDown = false;
} else if(e.keyCode == Keyboard.DOWN){
downDown = false;
}
}}
Copy link to clipboard
Copied
Trace the object being targeted in the two lines where you implement the hitTestObject method to see if it is coming up null. If so you need to determine why the object does not appear to exist as far as the code in that frame sees it.
trace("back.door is: "+back.door);
player.hitTestObject(back.door)
Copy link to clipboard
Copied
Sorry for disturb again, I already add on the coding, but it still doesn't work, why?
Copy link to clipboard
Copied
The code I say to add is to troubleshoot the problem, it will not solve it, but it could help lead to solving it if the file is able to compile. Does the trace show up in your output panel? If so, what does it indicate?
You should also go into your Flash section of the Publish Settings and select the option to Permit Debugging... that can help by adding a line number to the error message.
What is the 'door' object that is associated with the 'back' object? Does it exist in a frame that is not present when you try to run the file? If so, check to make sure that it has its instance name assigned in every keyframe it occupies.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now