同时删除事件监听器以及精灵AS3
我无法同时删除事件监听器以及精灵。我目前收到错误:
TypeError:错误#1009:无法访问
null对象的属性或方法
参考。
如果我注释掉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();
}
}
没有找到相关结果
已邀请:
2 个回复
提孺局缎
并找出为什么镜头为空。我怀疑在你提供的一点点代码之外的代码中有一些不妥之处。如果代码仅使用注释掉的removeChild行,则它告诉我e.currentTarget不为null,但它也不是对Bullet类型实例的引用(即“as”强制转换返回null)。
博沮富教全
至