The main problem is that you declare your arrow variable at the top of the code like this:
Now you've got a variable called myarrow, but if you were to trace out its value at this point, it would be null, because you haven't instantiated it yet. You don't instantiate it in your code until the point where your user presses the spacebar.
However, you start an ENTER_FRAME function right away that begins hit testing this arrow object against the other object:
ActionScript Code:
if(myobj.hitTestObject(myarrow))
Since the enter frame function starts running right away, but the arrow object hasn't been instantiated yet, flash complains with an error message that it can't hit test a null object:
Parameter hitTestObject must be non-null
To remedy this in your code, you might do something like this:
ActionScript Code:
function hit(e:Event):void
{
if(myarrow != null) {
if(myobj.hitTestObject(myarrow)) {
removeChild(myobj);
removeChild(myarrow);
won.text="You Won";
}
}
}
The outer if in the above code tests to see if myarrow is not null before it does any hit testing on it. This gets rid of the error. However, if you run the above, when you succeed in hitting the object with an arrow, you will get another error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
What's going on this time? Well, the first if test passes because myarrow is not null. Even though it's been removed from the display list, it still exists in memory. Also, believe it or not, the next if test also passes. Even though the two objects have been removed from the display list, they are still considered to be hitting each other! Since both if's pass the test, the code proceeds to do a removeChild on both of the objects
again. That's when the error kicks in, because you can't remove a child from the display list that's not on it. To remedy this error, you can further modify the outer if statement like this:
ActionScript Code:
function hit(e:Event):void
{
if(myarrow != null && myobj.stage) {
if(myobj.hitTestObject(myarrow)) {
removeChild(myobj);
removeChild(myarrow);
won.text="You Won";
}
}
}
Now the outer if test will fail if the myobj object has been removed from the stage, because its stage property will be null.
This cures the errors you were getting. But there are other problems with it (like keyboard lag, for one), so I rewrote it, and it's attached. The class files are included in there too, but I mostly didn't change those.