执行后删除实例2

时间:2013-05-02 11:16:40

标签: actionscript-3 flash-cs6

得到一个参数child必须是非null错误,这个代码对任何人都有帮助吗?

for (i=1; i<=4; i++)
{
    this["Box" + i].addEventListener(Event.ENTER_FRAME, Move);
    this["Box" + i].addEventListener(MouseEvent.CLICK, Action);
}
function Move(e:Event):void
{
    e.target.y -=  6;
    if (e.target.y <= 56)
    {
        MovieClip(e.target).removeEventListener(Event.ENTER_FRAME, Move);
        removeChild(getChildByName(e.target.name));
        Comment.text = "MISS";
        miss +=  1;
        score +=  0;
    }
}
function Action(event:MouseEvent):void
{
    if ((event.target.hitTestObject(bts1))&&(event.target.hitTestObject(bts2))&&(event.target.hitTestObject(bts3))&&(event.target.hitTestObject(bts4)))
    {
        MovieClip(event.target).removeEventListener(MouseEvent.CLICK, Action);
        removeChild(getChildByName(event.target.name));
        Comment.text = "PERFECT";
        perfect +=  1;
        score +=  10000;
    }
    else if ((event.target.hitTestObject(bts2)&&event.target.hitTestObject(bts3)&&event.target.hitTestObject(bts4))||(event.target.hitTestObject(bts1)&&event.target.hitTestObject(bts2)&&event.target.hitTestObject(bts3)))
    {
        MovieClip(event.target).removeEventListener(MouseEvent.CLICK, Action);
        removeChild(getChildByName(event.target.name));
        Comment.text = "GREAT";
        great +=  1;
        score +=  5000;
    }
    else if ((event.target.hitTestObject(bts3)&&event.target.hitTestObject(bts4))||(event.target.hitTestObject(bts1)&&event.target.hitTestObject(bts2)))
    {
        MovieClip(event.target).removeEventListener(MouseEvent.CLICK, Action);
        removeChild(getChildByName(event.target.name));
        Comment.text = "GOOD";
        good +=  1;
        score +=  2500;
    }
    else if ((event.target.hitTestObject(bts4))||(event.target.hitTestObject(bts1)))
    {
        MovieClip(event.target).removeEventListener(MouseEvent.CLICK, Action);
        removeChild(getChildByName(event.target.name));
        Comment.text = "BOO";
        boo +=  1;
        score +=  1000;
    }
    else
    {
        MovieClip(event.target).removeEventListener(MouseEvent.CLICK, Action);
        removeChild(getChildByName(event.target.name));
        Comment.text = "MISS";
        miss +=  1;
        score +=  0;
    }
 }

btw“bts1,2,3”是一个线条影片剪辑,鼠标点击事件发生问题,我想要的是当我克隆盒子时它将在“bts”上做一个hittest并且盒子将是用户点击后删除,如果用户没有点击则会在某一点消失

1 个答案:

答案 0 :(得分:0)

在删除子项之前,您必须删除附加到它的所有侦听器,ENTER_FRAMECLICK等。只需复制并粘贴相同的行(这是一个不好的练习,当它修复时你需要在这里进行一些重构)。