Copy link to clipboard
Copied
I am getting an error with my hitTestObject for the boss1 and I don't know how to fix it. The part which is getting the problem is in blue and everthing else is fine. I have tried to go on the degbug thing and that did not help...
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.text.TextField;
import flash.ui.*;
import flash.display.*;
public class Arrow extends MovieClip
{
var speed:Number = 25;
var game:Game;
var boss1:Boss1;
public function Initialise(e:Event)
{
this.rotation = Man.rot+180;
game = stage.getChildByName("root1") as Game;
boss1 = stage.getChildByName("root2") as Boss1;
}
public function Arrow()
{
this.addEventListener(Event.ENTER_FRAME,this.OnEnterFrame);
this.addEventListener(Event.ADDED_TO_STAGE,this.Initialise);
}
public function OnEnterFrame(e:Event)
{
x =x+Math.cos(rotation/180*Math.PI+80.1)*speed;
y =y+Math.sin(rotation/180*Math.PI+80.1)*speed;
if(this.y < -250) RemoveArrow();
for(var i in game.enemyList)
{
if(this.hitTestObject(game.enemyList))
{
game.enemyList.Damage(Bow.Damage);
if(game.enemyList.GetHealth() <= 0)
{
Man.Money += Math.ceil(Math.random()*4) + 1;
game.enemyList.RemoveWolf1();
game.enemyList.splice(i,1);
if(Man.age == 1)
{
Man.kills1 += 1;
}
if(Man.age == 2)
{
Man.kills2 += 1;
}
if(Man.age == 3)
{
Man.kills3 += 1;
}
if(Man.age == 4)
{
Man.kills4 += 1;
}
if(Man.age == 5)
{
Man.kills5 += 1;
}
if(Man.age == 6)
{
Man.kills6 += 1;
}
if(Man.age == 7)
{
Man.kills7 += 1;
}
}
RemoveArrow();
break;
}
}
for(var t in game.ccheifList)
{
if(this.hitTestObject(game.ccheifList
{
game.ccheifList
if(game.ccheifList
{
Man.Money += Math.ceil(Math.random()*30) + 5;
game.ccheifList
game.ccheifList.splice(t,1);
if(Man.age == 1)
{
Man.kills1 += 1;
}
if(Man.age == 2)
{
Man.kills2 += 1;
}
if(Man.age == 3)
{
Man.kills3 += 1;
}
if(Man.age == 4)
{
Man.kills4 += 1;
}
if(Man.age == 5)
{
Man.kills5 += 1;
}
if(Man.age == 6)
{
Man.kills6 += 1;
}
if(Man.age == 7)
{
Man.kills7 += 1;
}
}
RemoveArrow();
break;
}
}
if(this.hitTestObject(boss1))
{
Boss1.health -= Bow.Damage;
if(Boss1.health <= 0)
{
Man.Money += Math.ceil(Math.random()*100) + 100;
Boss1.remove = true;
}
RemoveArrow();
}
for(var r in game.caveList)
{
if(this.hitTestObject(game.caveList
{
game.caveList
if(game.caveList
{
Man.Money += Math.ceil(Math.random()*10) + 5;
game.caveList
game.caveList.splice(r,1);
if(Man.age == 1)
{
Man.kills1 += 1;
}
if(Man.age == 2)
{
Man.kills2 += 1;
}
if(Man.age == 3)
{
Man.kills3 += 1;
}
if(Man.age == 4)
{
Man.kills4 += 1;
}
if(Man.age == 5)
{
Man.kills5 += 1;
}
if(Man.age == 6)
{
Man.kills6 += 1;
}
if(Man.age == 7)
{
Man.kills7 += 1;
}
}
RemoveArrow();
break;
}
}
}
public function RemoveArrow()
{
this.removeEventListener(Event.ENTER_FRAME,this.OnEnterFrame);
this.removeEventListener(Event.ADDED_TO_STAGE,this.Initialise);
this.parent.removeChild(this);
}
}
}
You have a recurring function, the OnEnterFrame function, that is called over and over again. In that function you have a hitTest for an object whose value is stored in a variable, boss1. When you remove Boss1, the value that is stored in the variable boss1, the variable has no reference or value and so the hitTestFunction throws an error. It now has nothing to work with.
So, if you throw away the value stored in boss1, you either need to stop running the OnEnterFrame function or you need to byp
...Copy link to clipboard
Copied
It is helpful if you include the entire error message in your posting. It gives some idea of what to look for. Try enabling the option to Permit Debugging in your Publish Settings before getting the message again.
Also, if you could use a more visible color to show the problem code it would help. The light aqua-blue is hard to see
Copy link to clipboard
Copied
I have already thought of that and it says to me what I know already and doesn't say anything new. It says it is the code I have highlighted in blue. The whole error message is:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at Arrow/OnEnterFrame()
Just saying that is the Arrow code.
Copy link to clipboard
Copied
In your function Arrow you set up two event listeners. The first is an onEnterFrame that calls another function: OnEnterFrame and another: Initialize. In Initialize you set the values for the variables game and boss1. It looks like the function OnEnterFrame is looking for the variable boss1 before you give it a value. The solution may be as simple as changing the order that you set up those eventListeners or you may need to create a larger time gap between setting the variable's value and using that variable.
Copy link to clipboard
Copied
I have been thinking about your idea about the time gaps between the variable use and the variable making type thing. So I decided to put traces between it to see how long it how many frames apart they are. I found out as soon as it is fired it sets the variable value and then it has about 2 frames until it gives me the error. I tried mixing the code around a bit putting it in different orders but it still gave me the error #2007.
Copy link to clipboard
Copied
If you look at your code in that hitTestObject section, you have: Boss1.remove = true; I don't know what that does, but it looks like it might set the value of boss1 to void, or something like that. If that's the case then there's the problem.
Copy link to clipboard
Copied
The Boss1.remove removes the boss. I have tried the void thing but it still doesn't work, than I tried changing all the Man, Bow, Boss1 to a variable but I need to get at the public static variables (the variables on the man and the boss to keep track of what's going on) and it doesn't let me. I am still doing research about the things like the void function but haven't come across anything useful, yet.
Copy link to clipboard
Copied
I can't really give you any good guidance on what you should do here. I don't know what else is going on. Why are you removing Boss1? Are you "killing" the player or something like that?
One thing to consider is that if you remove Boss1, do you now not need to continue running the function OnEnterFrame? If that's the case then you could remove the event listener when you remove Boss1. That will stop the function from continuing.
Copy link to clipboard
Copied
I am removing Boss1 because he would have died so he is dead. The problem is not when he dies but when the arrow is trying to test for the arrow hitting the boss. That's what I've understood anyway. But I don't know how to solve it. From what I've read about the error is that the (boss1) after the hitTestObject which is the problem. I have already tried using the Boss1 (which is the codes name) but it needs get it from the root (that's what the bit in the Initialise function) And I don't know how to do that anyway else.
Copy link to clipboard
Copied
You have a recurring function, the OnEnterFrame function, that is called over and over again. In that function you have a hitTest for an object whose value is stored in a variable, boss1. When you remove Boss1, the value that is stored in the variable boss1, the variable has no reference or value and so the hitTestFunction throws an error. It now has nothing to work with.
So, if you throw away the value stored in boss1, you either need to stop running the OnEnterFrame function or you need to bypass the section of the function that does the hit test.
Does that help to explain the problem?
Copy link to clipboard
Copied
yes that does. Thank you! I will do that now.
Copy link to clipboard
Copied
Thank you very much! I have completed it. I realised that I was spawning the boss in so I put the boss in a list in my game code. So now it is very similar than the other hitTestObject bits of code.
Copy link to clipboard
Copied
I'm glad that you worked it out. Good luck with your project.