0

如何解决Parameter child must be non-null错误?
我正在尝试删除具有.y <= 56

代码如下:

for (i=1; i<=4; i++)
{
    this["Box" + i].addEventListener(Event.ENTER_FRAME, Move);
}

function Move(e:Event):void
{
    e.target.y -=  6;
    if (e.target.y <= 56)
    {
        removeChild(getChildByName(e.target.name));
        Comment.text = "MISS";
        miss +=  1;
        score +=  0;
    }
}
4

3 回答 3

1

AS 区分大小写(如 99% 的语言)。

您的实例名称实际上是大写的 ( Box) 还是全小写的 ( box) ?

于 2013-05-02T08:40:18.470 回答
1

似乎侦听器在删除框后继续触发,所以在此行之前:

removeChild(getChildByName(e.target.name));

添加这一行:

MovieClip(e.target).removeEventListener(Event.ENTER_FRAME, Move);
于 2013-05-02T08:49:08.850 回答
1

如果框是 MovieClip(或扩展 MovieClip):

var currentBox:MovieClip = MovieClip(e.target);
currentBox.y -=  6;    
if (currentBox.y <= 56) {
    currentBox.removeEventListener(Event.ENTER_FRAME, Move);
    removeChild(currentBox);
    Comment.text = "MISS";
    miss +=  1;
    score +=  0;
}
于 2013-05-02T08:49:15.723 回答