ForumsProgramming Forumas3 Collision decetion attempt, error 1009?

13 5043
Theheyjude
offline
Theheyjude
114 posts
Nomad

so to start off heres the exact error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
and my code:

import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent

var gameTimer:Timer;

addEventListener(Event.ENTER_FRAME,downspike)
function downspike(e:Event):void{
function downspike( timerEvent:TimerEvent ):void{

gameTimer = new Timer(25)
gameTimer.addEventListener(TimerEvent.TIMER, downspike)
gameTimer.start()

}


Spike.x=218;
Spike.y=0;

y=y+10

Player.x=mouseX;
Player.y=mouseY;



if(Player.hitTestObject(Spike) )
{
gameTimer.stop()
}
}

so i know my code is super sloppy. i started of thinking i was going code it all on my own then i ended up needing help and stupidly tried to add stuff from a tutorial.
i probaly should just erase the stuff from the tutorial and attempt it myself. but im at a lose anyway... so with my code i have a spike coming down and a ball that follows my mouse and i was hoping that when the two hit it would be a crude game over type thing but it would really just freeze. but rather it gave me that error. so anybody who feels up to helping me can choose one of two options. either help me try and fix this coding. or suggest a better way to make it well the spike hits the ball its a sense of game over

  • 13 Replies
25wes25
offline
25wes25
1,584 posts
Nomad

I think it said you need a null object i could fix it but pretty hard just go to tutorialized.com and look through the 24 page flash game tuts.

Theheyjude
offline
Theheyjude
114 posts
Nomad

will do, thanks for the site. its great

25wes25
offline
25wes25
1,584 posts
Nomad

np need any more help contact me on my page goodluck man id love to beta test ur game

BeastMode10
offline
BeastMode10
374 posts
Nomad

I'm not sure if 2 'downspike' functions can exist simaltaneously...

Theheyjude
offline
Theheyjude
114 posts
Nomad

lol beastmode i didn't even realise that till now. it was fixed a long time ago when i just erased it and tried something else

but anywho im here cause im about to die of insanity! (i think im the first person to ever think of insanity as a way of death... kudos me) anywho i have the capability to code the entirety of this game im making except for one part... collision decetion. i tried wes's tut site and tried like a million tut's but i couldn't figure them out! really all i need is for the game to stop when they hit. if i could just get it so that it appears to freeze and do nothing else when they collide i could work from there but i can't fiqure it out! i know to use the hittestobject i have to make it so that something happens when they collide but i don't know any codeing that can help me! if anyone could help that would be a miracle

25wes25
offline
25wes25
1,584 posts
Nomad

Are you wanting ur guy to die or like stop as if its a wall?

Theheyjude
offline
Theheyjude
114 posts
Nomad

I want him to die. I want it to eventally make it so that when he hits a object it goes to a gameover screen

25wes25
offline
25wes25
1,584 posts
Nomad

Oh to a hit test that says like:
onClipEvent (enterFrame) {
this._y += speed;//moves the enemy downwards
if (this.hitTest(_root.player)) {//if the enemy hits the player
_root.gotoAndStop(2);//goto the second frame, which will be a gameover screen

}

Then make a frame 2 or next frame that is the game over screen.

Theheyjude
offline
Theheyjude
114 posts
Nomad

thats perfect dude thanks a ton

25wes25
offline
25wes25
1,584 posts
Nomad

np always happy to help

Theheyjude
offline
Theheyjude
114 posts
Nomad

ok one last question youve been a giant help but i have used this code before.

so i copied and pasted the code and i got a bunch of errors for enterFrame
and the onClipEvent
and _root .

all saying it is undefined

so i was wondering. do i need to put in a function or var or class or something?

P.S i was using diffrent code for the enemy to move down and i see you included code for that. should i use your code or the code i was using which is a simple:

y=y+10

25wes25
offline
25wes25
1,584 posts
Nomad

Try both use one that works.

Theheyjude
offline
Theheyjude
114 posts
Nomad

kk

Showing 1-13 of 13