Removing instance after several condition

How do i solve the Parameter child must be non-null error? I'm trying to remove instances (box1, box2, box3, box4) that have .y <= 56

The code follows:

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;
    }
}

Answers


Seems like listener continue to fire after the box is removed, so before this line:

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

add this line:

MovieClip(e.target).removeEventListener(Event.ENTER_FRAME, Move);

If box are MovieClip (or extend 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;
}

AS is case-sensitive (like 99% of languages).

Are your instances' names actually capitalized (Box) or all-lowercase (box) ?


Need Your Help

Angularjs directive isolated scope properties undefined

angularjs angularjs-directive

I am trying to integrate a jqeury control (http://amsul.ca/pickadate.js/) into my angular app using a directive, however within my directive I have an isolated scope but the object type properties ...

Using Windows Authentication with ASP.NET 3.5 Website

asp.net iis iis-7 active-directory dns

If I have a user base that operates on DomainA, and an ASP.NET website that resides/runs on DomainB could I use Windows Authentication as an authn type if they are accessing through the browser? AD...

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.