removing instance after excecuted 2

got an Parameter child must be non-null error with this code anyone can help ?

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 the "bts1,2,3" is a line movie clip the problem occur on the mouse click event, what i want is when i clik the box it will do a hittest on the "bts" and the box will be remove after user click, if the user didn't click then it will disappear at certain point

Answers


Before you removing child , you must to remove ALL listeners attached to it , ENTER_FRAME and CLICK etc . Simply copy and paste the same lines (it's a little bit bad practice , when it will be fixed you'll need to make some refactoring here).


Need Your Help

How to Iterating through an JSON Object and append an HTML input menu/list select

php javascript html json getjson

I've searched on here and tried several solutions offered with no luck. I have a html input menu/list select that I want to populate with options after the user inputs into an input text box. Once ...