Copy link to clipboard
Copied
Hi guys, almost done with my game, but I'm having some major problems regarding flash throwing 2 errors in the end-screen of my game.
Was wondering if anyone could help me and tell me where the problem is to be found? I'm a real AS3 newbie and my head has had a try at it for the last 1 hour or so. Ive tried to read up on what those errors really say, but i still havent managed to lurk out the problems. Would appriciated if anyone could download the "game", give it a run and see if you can see why Flash is throwing errors.
To "experience" the error, just start the game in Flash (so you can see the debugger), and let one of the objects flying from the roof hit you. You will then see an endgame screen and a hidious ammount of errors being thrown.
I've uploaded the file to one of my servers, and you can download the "whole package" here; http://enavdebedre.com/itspill.zip . Its a .zip archive, size is about 11.4mb. Contains the whole project needed to run and debug.
Would really appriciate if anyone has any inputs to share on the problem.
Thanks!
Message was edited by: RedITYesterday Edited so it was a .zip archive instead of .rar!
Copy link to clipboard
Copied
You'll increase your chances of getting help if you don't require people to look beyond your posting for the information they need to try to help solve your problem. Not many are willing to download files. If you could put the actual error messages in your posting that is a good start, as well as including any code that might be relevant to the errors.
The 1009 error indicates that one of the objects being targeted by your code is out of scope. This could mean that the object....
- is declared but not instantiated
- doesn't have an instance name (or the instance name is mispelled)
- does not exist in the frame where that code is trying to talk to it
- is animated into place but is not assigned instance names in every keyframe for it
- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).
If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.
Copy link to clipboard
Copied
Thank you again.
Ok, so im Assumeing that the problem is in fact that the object "- does not exist in the frame where that code is trying to talk to it" as you said it.
But, i've used "countermeasures" to work against this (removechild, eventlisteneres etc.) , and it still won't give up.
I think its the "HitTestObject" messing up, its trying to "hittest" with a object which is not in the next frame, but i haven't told it to keep checking.
Is there any way to stop the "hitTest" from running? like a "HitTest.stop" or something? Ive tried googling now but it doesent seem to help.
Relevant code:
//hit testing with the user
if(hitTestObject(_root.mcMain)){
//losing the game
_root.gameOver = true;
_root.gotoAndStop('lose');
}
if(_root.gameOver){
removeEventListener(Event.ENTER_FRAME, eFrame);
this.parent.removeChild(this);
}
Relevant Errors;
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Enemy/eFrame()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
Does this make for better troubleshooting?
Copy link to clipboard
Copied
How are you defining "_root"? That is an AS1/AS2 term and will not work in AS3.
If you are somehow legitimately defining _root, what is causing that code to execute mutliple times? Is it inside a function named eFrame?
You can see if the object being targeted is coming up null if you use the trace() function just before that line. Use trace(_root.mcMain) and see if it comes up null (or doesn't trace)
Copy link to clipboard
Copied
Thanks yet again, Ned.
"_root" is defined in the following way:
private var _root:Object;
It is indeed inside a function named "eFrame", the source for that part is the following;
private function eFrame(event:Event):void{
//moving the bullet up screen
y += speed;
//making the bullet be removed if it goes off stage
if(this.y > stage.stageHeight){
removeEventListener(Event.ENTER_FRAME, eFrame);
_root.removeChild(this);
}
I tried trace'eing right above the line and it returned a null, so that is where the problem probably is. Although you now have located the problem for me, how can i be able to stop it from being null?
Ive tried to add "_Root.mcMain" into the last frame (the movieclip), but i then get referenced to another null-error, aswell as another type of error towards the HitTest again.
Is there any code available to "Shut down" the HitTest code i wrote earlier once it actually detects a hit?
Copy link to clipboard
Copied
While this might be side-stepping the real issue, you could try including the test for _root.mcMain existing as part of that code
if((_root.mcMain != null){
if(hitTestObject(_root.mcMain)){
It will be more suitable if you can shutdown the test altogether, which I have to think is happening in the line where you remove the ENTER_FRAME listener. Is the error coming up immediately or before a hit occurs or is it occuring after a hit occurs?
You basically need to hunt down why you keep testing for a hit when the object no longer exists and stop that testing.
Copy link to clipboard
Copied
Thanks again, Ned.
I tried your code-snippet, still kicks out with the same error, weird enough, shouldnt it not proceed if there is a null?
The error is comming up after the hit occurs. When the hit occurs, it jumps to a new frame and then the errors start punching in.
Im pretty tired of this now, Ive tried of everything my dumb little newbie-AS brain can think of, im thinking on giving up. Debugging this seem to extend my knowledge a couple of hundred times.
Copy link to clipboard
Copied
Don't give up but take a break if it's saturated your thinking. I often solve things when I am removed from them. You basically need to figure out how to shut down the eFrame function calls before you change frames.
Copy link to clipboard
Copied
There are tons of errors. As far as the first one on line 58 in Enemy class is concerned - you need to check for if _root.mcMain exists. So the line
if(hitTestObject(_root.mcMain)){
should be
if(_root.mcMain && hitTestObject(_root.mcMain)){
Because at some point of the game _root.mcMain sieze to exist.
Also, it is an overkill to have a separate _root Object because, unlike in AS2, root is stable in AS3 and you can refer to it directly.
There are more errors there - you always need to check for objects existence in your code. I suspect there are some logical flows but I don't have time to debug more.
Copy link to clipboard
Copied
Also, on main timeline, there is an error on line 48. The following addition to moveChar function eliminates the error as well:
function moveChar(event:Event):void{
if(!mcMain){
return;
}
// the rest of the code
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now