Hi,
I’ve read many many articles and I’ve asked others if the can help, but I’m stumped. The functionality I’m looking for apparently works in CS5 of as3, but it’s not working in my cs4 version of as3.
This is what I’m trying to do. I’ve created a first person shooter game. I have bullets come out of a gun and hit the bad guys. When the bad guys are hit, I want to do the following -
- make the bad guy and bullet invisible - done, works.
- remove all references to both the bad guy object and bullet object - done, seems to work.
- delete the bad guy object and the bullet object from the stage - doesn’t work, can’t seem to figure out why not.
Here’s some snippets of my code, let me know if you need to see more -
function cleanUpObjects(evt:Event) {
var m:Number;
for (m = 0; m < stageBulletArray.length; m++) {
if (stageBulletArray[m].z > 500) {
trace("My object " + stageBulletArray[m] + " has reached 500 at position " + m);
stageBulletArray[m].visible = false;
trace("Current object " + stageBulletArray[m] + " is invisible");
//added to TME 3 - test and validate - done/works
removeObject(stageBulletArray[m]);
delete stageBulletArray[m];
trace("Exited removeObject function");
}
}
}
/*
removeObject - This function was added for TME3. It's used for removing objects and references to
objects so that they can be garbage collected later on by the flash player. First, references are
removed and then the object is removed from it's parent (if it has any).
*/
function removeObject(myObject:Sprite):void {
trace("in removeObject function");
//remove the EventListeners or references from the object
myObject.removeEventListener(Event.ENTER_FRAME, moveBullet);
myObject.removeEventListener(Event.ENTER_FRAME, bulletHit);
myObject.removeEventListener(TimerEvent.TIMER, makeZombie);
myObject.removeEventListener(MouseEvent.CLICK, fireBulletHandler);
myObject.removeEventListener(Event.ENTER_FRAME, moveZombieYOne);
myObject.removeEventListener(Event.ENTER_FRAME, moveZombieYTwo);
myObject.removeEventListener(Event.ENTER_FRAME, moveZombieYThree);
trace("all events removed for " + myObject);
// traceDL(myObject, 1);
//test to see if the object has a parent and then remove the object from it's parent. This
//should allow the object to be available for garbage collection on the next pass.
// delete myObject;
// stage.setChildIndex(myObject, 0);
// stage.removeChildAt(0);
// while (myObject.parent != null) {
// myObject.parent.removeChild(myObject);
// myObject = null;
// trace("object removed from parent: " + myObject.parent);
trace("the object removed is: " + myObject);
// }
}//~end removeObject function
This is the error on the output I’m getting - it seems to be happening at the delete stageBulletArray[m]; line -
My object [object Bullet] has reached 500 at position 0
Current object [object Bullet] is invisible
in removeObject function
all events removed for [object Bullet]
the object removed is: [object Bullet]
Exited removeObject function
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at tme3_Scene2_fla::MainTimeline/bulletHit()
TypeError: Error #1010: A term is undefined and has no properties.
at tme3_Scene2_fla::MainTimeline/cleanUpObjects()
I’m stumped and I’ve been stuck for months on this. Any ideas? Here’s my hit test code -
function bulletHit(evt:Event) {
var a:Number;
var b:Number;
for (a = 0; a < stageZombieArray.length; a++) {
for (b = 0; b < stageBulletArray.length; b++) {
if (stageZombieArray[a].hitTestObject(stageBulletArray**)) {
//need to test logic
if (((stageBulletArray**.z + 5) <= stageZombieArray[a].z) && (stageBulletArray**.z >= (stageZombieArray[a].z - 5))) {
trace("bullet and zombie hit in z space");
//remove the zombie from the stage
stageZombieArray[a].visible = false;
scoreText.text = "Zombies Killed: " + zombieHit++;
//added for tme 3 - need to test
removeObject(stageZombieArray[a]);
//remove the bullet from the stage
stageBulletArray**.visible = false;
//added for tme 3 - need to test
// removeObject(stageBulletArray**);
} //~ if loop - test that zombie and bullet are near each other in z space
} //~end if loop - test that zombie and bullet hit one another
} //~end inner for loop - counts bullets on stage
} //~end outer for loop - counts zombies on stage
}//~ end bulletHit function
Thanks in advance!