PDA

View Full Version : [AS3] Error! help with game


T24
01-04-2009, 04:10 PM
I'm having a problem with a puzzle game that I'm working on. Everything seems to be working fine, until level 2 of the game. Once you're on level 2 the timer starts and everything seems fine - until you click a puzzle piece to pick it up and then drop it (in other words, on level 2, when you click a piece I receive the following error).

TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at HitTest$/complexIntersectionRectangle()
at HitTest$/complexHitTestObject()
at puzzleGame_fla::MainTimeline/shapeHitTest()
at puzzleGame_fla::MainTimeline/stopDragage()

However, the game still functions properly, and, if you ignore the error, you could actually finish level 2 as if the error didn't even occur. I tried to debug the movie but I didn't get much out of it. It seems the problem is with the script in the hit test.

Download the files and check it out (I used Flash CS4 to create the game - A.S. 3.0). The game is not complete but you can still play it. Play the game and once you get to level 2, click on a piece and you will get the error. Maybe you could figure it out or offer some suggestions.

Thanks in advance!

Download the flash file (puzzleGame.fla), and a.s. file which contains the script for the hit text/ collision (HitTest.as). They are both in .zip I couldn't upload the flash file here because it was too large but you can download it from the link I gave you.

http://www.mediafire.com/?tdylntcjtnn << puzzleGame.zip

Rossman
01-04-2009, 05:15 PM
Wherever your line is that's doing the "hitTestObject", just check the parameter with an if statement so that you won't do it if the parameter is null?


if( target != null )
{
if ( this.hitTestObject( target ) )
{
// collision
}
}

rrh
01-05-2009, 01:47 AM
You're deleting something from the first level, but still have

I took a look at your HitTest class. It's just full of static functions, so I expect one of those functions is being passed a null value. So you might want to check the places where those functions are being called, and what they are passing to it.

T24
01-07-2009, 11:49 PM
Thanks very much for your suggestions! I haven't had the chance to edit the game yet but I will try what you guys said - it seems like you have the answers.

I did not write the hit test, I'm just using it for my game to test the collision between the puzzle pieces - I will have a look at it though and check the functions.

rrh
01-08-2009, 05:57 AM
Whoops, looks like I didn't finish my thought. I was probably going to say:
You're deleting something from the first level, but still have that something in a variable that's being treated as though it's still there.

So it's probably those puzzle pieces. You're removing the puzzle pieces from the stage but aren't removing them from your list of pieces to check for collision.

T24
01-19-2009, 02:07 AM
Sorry guys but it turns out I still don't have the answer :(
I just don't know what is happening, It seems I've written the code correctly and the game would still work properly if the error was ignored. What is the difference between a static/ non-static function?

Do you guys know anybody that is really good with hit test/ actionscript 3.0 and has Flash CS4 so he can play my game and check the error.

rrh
01-19-2009, 02:09 PM
Static functions can be called through a reference to the class itself, so that it doesn't require an instance of the class.

Go through your code in shapeHitTest() and find where you are calling complexHitTestObject() and what are the values of what you are passing. If any of them are undefined, figure out why.

T24
01-22-2009, 01:05 AM
OMG YES! I have found the solution!

In the first level I added an event listener to the stage that calls a function (when the mouse is released) which ultimately checks the collision between the level 1 shapes. So then you go and beat level 1 and get to level 2. You click on a level 2 shape and release the mouse and then I receive that error. When I release the mouse in level two is calls that function from level one (and checks the collision between level 1 shapes - which are no longer display objects and therefore the static function in the Hit test is being passed a null value - the display objects to be tested for collision no longer exist on the stage) because of the event listener I added when the mouse is released on the stage.

So all I had to do is add some code to remove the event listener when you get to level 2.

Thanks for your help, I might not have found it without your suggestions but I'm so glad I have that problem fixed now!