我无法同时删除事件侦听器和精灵。我目前收到一个错误:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。
如果我注释掉 removeChild,我没有错误,但显然,精灵仍然在屏幕上。有什么想法可以让我自己摆脱这个错误吗?
//Bullet extends Sprite Class
bullet:Bullet = new Bullet();
mc.addChild(bullet);
bullet.addEventListener(Event.ENTER_FRAME, shoot);
function shoot(e:Event):void {
var shot:Bullet = e.currentTarget as Bullet;
//check shot is outside the frame
if (shot.x < 0 - shot.width || shot.x > stage.stageWidth || shot.y > 525)
{
//trying to remove the thing and it's listener
e.currentTarget.removeEventListener(e.type,arguments.callee);
e.currentTarget.parent.removeChild(shot);
}
else
{
shot.setInMotion();
}
}