0
votes

I'm trying to remove MovieClip but it says Parameter child must be non-null.

This My Script:

To make it in stage, i use:

function sayam (e:MouseEvent):void{
    nilai = 8;
    if(nilai == temp) {
    var ssAyam:ayam_mc = new ayam_mc
    stage.addChild(ssAyam);
    ssAyam.x = 350.0;
    ssAyam.y = 330.0;
    ssAyam.width = 170.0;
    ssAyam.height = 170.0;
    ssAyam.instanceName = "Ayam";
    arnam.push("Ayam");
    trace("arnam" +arnam);
    trace(ssAyam.instanceName);
    jual = jual + 4000;
    temp = val[len-(len-len2)]
    len2 = len2 + 1;
    } else {
            money = money - 4000;

        }

    }

So, i made 8 functions to make 8 movieclips to display in stage and push them to array. The Array is "arnam".

and this is my remove code:

function deleteBurger() {
                for(var i:Number=arnam.length; i >= 0; i--){
                        removeChild(arnam[i]);
                        arnam.splice(i,1);
                }
            }

I've traced my array and it isn't null.

can anybody help me? thank you :)

3

3 Answers

1
votes

You shouldn't modify an array in a loop based on this array's length, the behaviour would be unpredictable.

for each(var child:Sprite in arnam){
    stage.removeChild(child);
}
arnam = [];
2
votes

I like to do this to zero out an array and manipulate the members as I do so:

while( arnam.length )
{
    removeChild( arnam.pop() );
}

Now, I would use a Vector of MovieClips, to strongly type, rather than an Array. And also use contains() to check that the MovieClip is still on stage before trying to remove it :)

0
votes

try this

for(var i:int=arnam.length-1; i >= 0; i--){
                        removeChild(arnam[i]);
                        arnam.splice(i,1);

                }