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

Condense/merge cells in a table in R

r table split

I'm trying to do something with a table in R.

Compatible device list for iOS app

iphone xcode ios itunes

How can I specify the compatible devices for my iphone app? I can see a compatible device list (e.g.: iPhone 3GS, iPhone 4) for several apps in iTunes but how can i set this for my own app?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.