0
votes

I have a class that controls an enemy. From within that class, it checks for collisions with an array on the main timeline. I've done it this way before and it works fine, so I have no idea what I've done wrong this time. It keeps giving me an

ReferenceError: Error #1069: Property bulletArray not found on flash.display.Stage and there is no default value.

error from within the enemy class.

Here's my code (shortened to remove the unimportant parts): On timeline:

var bulletArray:Array = new Array();
function shoot(e:TimerEvent)
{
    var bullet:MovieClip = new Bullet(player.rotation);
    bullet.x = player.x;
    bullet.y = player.y;
    bulletArray.push(bullet);
    stage.addChild(bullet); 
}

In class:

private var thisParent:*;
thisParent=event.currentTarget.parent;

private function updateBeingShot()
        {

            for (var i=0; i<thisParent.bulletArray.length; i++) {
                if (this.hitTestObject(thisParent.bulletArray[i]) && thisParent.bulletArray[i] != null) {
                    health--;
                    thisParent.bulletArray[i].removeEventListener(Event.ENTER_FRAME, thisParent.bulletArray[i].enterFrameHandler);
                    thisParent.removeChild(thisParent.bulletArray[i]); 
                    thisParent.bulletArray.splice(i,1);
                }
            }

Any help would be greatly appreciated! Thanks.

2
You might want to paste the package and class declaration, and the event listener where you assign thisParent, so we can get an idea of how you have set everything up. - weltraumpirat

2 Answers

0
votes

My guess is that event.currentTarget is the instance where you declared the bulletArray variable. Using event.currentTarget.parent will refer to stage outside your scope. I don“t know how you declare the listeners. Try using event.target instead of event.currentTarget and see if you get the same error.

My advice is that you put all your code in a class.

0
votes

If you are going to do it this way you need to pass in a reference to the timeline.

private var _timeline:Object;

// constructor 
public function YourClass(timeline:Object) {
    _timeline = timeline;
}

private function updateBeginShot() {
    // ..
    trace(_timeline.bulletArray); // outputs [array contents]
    // ..

}