Community

as3 Collision decetion attempt, error 1009?

Posted Sep 3, '10 at 6:58pm

Theheyjude

Theheyjude

108 posts

Wood - Squire

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

Posted Sep 3, '10 at 8:55pm

25wes25

25wes25

320 posts

Gold - Squire

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.

 

Posted Sep 3, '10 at 10:11pm

Theheyjude

Theheyjude

108 posts

Wood - Squire

will do, thanks for the site. its great

 

Posted Sep 3, '10 at 10:21pm

25wes25

25wes25

320 posts

Gold - Squire

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

 

Posted Sep 3, '10 at 11:35pm

BeastMode10

BeastMode10

371 posts

Gold - Squire

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

 

Posted Sep 4, '10 at 12:04am

Theheyjude

Theheyjude

108 posts

Wood - Squire

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

 

Posted Sep 4, '10 at 1:24am

25wes25

25wes25

320 posts

Gold - Squire

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

 

Posted Sep 4, '10 at 12:56pm

Theheyjude

Theheyjude

108 posts

Wood - Squire

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

 

Posted Sep 4, '10 at 2:42pm

25wes25

25wes25

320 posts

Gold - Squire

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.

 

Posted Sep 4, '10 at 3:16pm

Theheyjude

Theheyjude

108 posts

Wood - Squire

thats perfect dude thanks a ton

 

Posted Sep 4, '10 at 3:35pm

25wes25

25wes25

320 posts

Gold - Squire

np always happy to help :)

 
Reply to as3 Collision decetion attempt, error 1009?

You must be logged in to post a reply!