mercredi 23 décembre 2015

Removing MC from array AS3

I am having a problem removing a MovieClip from an array.

I am getting the error "TypeError: Error #1009: Cannot access a property or method of a null object reference. at Spiker/loop()".

The spike (Spiker) is getting removed, but the error still annoys me.. Any idea how to fix this?

Thanks

package  {

import flash.display.MovieClip;
import flash.events.Event;

public class Spiker extends MovieClip {

    public var spikeDirection:int = 1;
    private var removed = false;
    public function Spiker() {
        // constructor code
        trace("Spiker added");

        addEventListener(Event.ENTER_FRAME, loop);
    }
    private function loop (evt){
        this.x += spikeDirection * 10;

        for(var i:int = 0; i < this["parent"].enemyList.length; i++){
            if(removed == false){
                if(this["parent"].enemyList[i].hitTestObject(this)){
                    trace("Spikerhit");
                    removed = true;
                    remove(evt);
                }
            }
        }
    }
    public function remove (evt){
        removeEventListener(Event.ENTER_FRAME, loop);
        this["parent"].removeChild(this);
    }

}

Aucun commentaire:

Enregistrer un commentaire