Copy link to clipboard
Copied
I'm Having A Recurring Error That Says "TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at VideoGameGravityTest_fla::MainTimeline/hitTest()"
This Happens When I Go From Frame 4 To Frame 1, The code for Frame 1 Is:
stop();
import flash.events.Event;
winner.visible = false;
stage.addEventListener(Event.ENTER_FRAME, hitTest)
var counter = 0;
function hitTest(evt: Event)
{
score.text = counter;
ball_mc.x = mouseX;
ball_mc.y = mouseY; {
if (counter > 0){
score5.text = "HIT!"
}
if (counter > 10) {
score2.text = "Nice!"
}
}
if (counter > 100) {
score2.text = ""
score3.text = "Almost Their!"
}
if (counter > 199) {
score.text = ""
score3.text = ""
score4.text = "Click ->"
john.x = 497
winner.visible = true
score5.visible = false
}
if (ball_mc.hitTestObject(wall_mc)) {
counter += 10
}
}
john.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
function fl_ClickToGoToAndStopAtFrame(event: MouseEvent): void {
gotoAndStop(4);
john.removeEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame);
stage.removeEventListener(Event.ENTER_FRAME, hitTest)
}
And the code for frame 4 is:
stop();
var bobb: int = 0;
count.text = "" + bobb;
ball_mc.x = 2000
uhoh.visible = false
var flyup: Boolean = false;
var flydown: Boolean = false;
var shoot: Boolean = false;
bullet.stop();
boom.stop();
exit3.x = 2000
ship.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_6);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_6);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_6);
bullet.addEventListener(Event.ENTER_FRAME, destroy);
function fl_MoveInDirectionOfKey_6(event: Event) {
if (ship.y > 440){
ship.y = 440
}
if (ship.y < 40){
ship.y = 40
}
if (flyup) {
ship.y -= 10;
}
if (flydown) {
ship.y += 10;
}
if (shoot) {
bullet.y = ship.y
bullet.y += 40
bullet.play();
words2.x += 2000
}
}
function fl_SetKeyPressed_6(event: KeyboardEvent): void {
switch (event.keyCode) {
case Keyboard.W:
{
flyup = true;
break;
}
case Keyboard.S:
{
flydown = true;
break;
}
case Keyboard.SPACE:
{
shoot = true;
break;
}
}
}
function fl_UnsetKeyPressed_6(event: KeyboardEvent): void {
switch (event.keyCode) {
case Keyboard.W:
{
flyup = false;
break;
}
case Keyboard.S:
{
flydown = false;
break;
}
case Keyboard.SPACE:
{
shoot = false;
break;
}
}
}
function destroy (evt:Event){
if (bullet.hitTestObject(asteroid1)){
asteroid1.y += 20000
boom.y = bullet.y
boom.x = 535
boom.play();
boom.y -= 55
bullet.gotoAndPlay(1)
bobb++;
count.text = "" + bobb;
}
if (bullet.hitTestObject(asteroid2)){
asteroid2.y += 20000
boom.y = bullet.y
boom.x = 560
boom.play();
boom.y -= 55
bullet.gotoAndPlay(1)
bobb++;
count.text = "" + bobb;
}
if (bullet.hitTestObject(asteroid3)){
asteroid3.y += 20000
boom.y = bullet.y
boom.y -= 55
boom.x = 500
boom.play();
bullet.gotoAndPlay(1)
bobb++;
count.text = "" + bobb;
}
if (bobb > 2){
uhoh.visible = true
uhoh.addEventListener(Event.ENTER_FRAME, mee);
function mee (evt:Event){
if (bullet.hitTestObject (uhoh)){
gotoAndPlay (5)
ship.removeEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_6);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_6);
stage.removeEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_6);
stage.removeEventListener(Event.ENTER_FRAME, mee);
bullet.removeEventListener(Event.ENTER_FRAME, destroy);
ship.x += 2000
bullet.x += 2000
}
}
}
if (asteroid1.x < -30){
gotoAndPlay(1)
ship.removeEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_6);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_6);
stage.removeEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_6);
uhoh.removeEventListener(Event.ENTER_FRAME, mee);
}
if (asteroid3.x < -30){
gotoAndPlay(1)
ship.removeEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_6);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_6);
stage.removeEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_6);
uhoh.removeEventListener(Event.ENTER_FRAME, mee);
}
if (asteroid2.x < -30){
gotoAndPlay(1)
stage.addEventListener(Event.ENTER_FRAME, hitTest)
ship.removeEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_6);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_6);
stage.removeEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_6);
uhoh.removeEventListener(Event.ENTER_FRAME, mee);
}
}
If you have any ideas on how to fix this let me know
Copy link to clipboard
Copied
click file>publish settings>tick permit debugging. retest.
note the frame (and line) triggering the error (which i suspect will be the frame 1 hittestobject) where that stage listener is still executing and you probably don't have wall_mc.
Copy link to clipboard
Copied
Hello Thanks for the help about it, so after I turned on the tick permit debugging it says:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at VideoGameHelp_fla::MainTimeline/fl_MoveInDirectionOfKey_6()[VideoGameHelp_fla.MainTimeline::frame4:21]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at VideoGameHelp_fla::MainTimeline/destroy()[VideoGameHelp_fla.MainTimeline::frame4:87]
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at VideoGameHelp_fla::MainTimeline/hitTest()[VideoGameHelp_fla.MainTimeline::frame1:40]
On frame 4 line 21 it says:if (ship.y > 440)
On frame 4 line 87 it says : if (bullet.hitTestObject(asteroid1))
And On Frame 1 line 40 it says if (ball_mc.hitTestObject(wall_mc)
if you have any more questions on things you might need to help figure this out for me let me know.
Copy link to clipboard
Copied
update on it i deleted my current wall_mc remade the symbol so the error on frame1 line 40 is no longer a issue, just the ones on frame4 line 87 and frame 4 line 21
Copy link to clipboard
Copied
I fixed the frame 4 line 21 problem, im still stuck on the frame 4 line 87:
if (bullet.hitTestObject(asteroid1))
Copy link to clipboard
Copied
bullet is gone, or been nulled. ie, what's happening on frame 1 of bullet? is that an frame with nothing on stage?
Copy link to clipboard
Copied
ok nevermind on everything. thanks for the help
Copy link to clipboard
Copied
don't do that. other people check these threads and your solution might help someone else.
is the problem resolved? if so, how did you resolve it?
Copy link to clipboard
Copied
well i just added the missing non null object references to frame 1 cause it said it could not acsess it
Copy link to clipboard
Copied
thank you for the follow up.