views:

289

answers:

1

In my game, I encapsulate my addChild so that I can have an array of all the objects that are on stage for later garbage collection. this is how I do so

public function addGameChild(object:gameObject,isDisplay:Boolean = true):void
        {
            if(isDisplay)
                addChild(object);

            gameStage.push(object);
        }

It adds it just fine. Later, I check to see if its ready for garbage. this

private function loop(e:Event):void {

            for(var t = 0; t < gameStage.length; t++)
            {               
                gameStage[t].updateObject();
            }

            for(var g = 0; g < gameStage.length; g++)
            {               
                if(gameStage[g].garbage)
                {
                    removeChild(gameStage[g]);
                }
            }
        }

each gameObject has a property called garbage that is a boolean that is set when ready to be removed. When I set it to tree, this is what happens

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

anyone have any clue on whats happening ?

A: 

Figure it out. I forgot to splice(g,1) the object after removing it. It looped again and tried to remove the object again and thats when the error was thrown

numerical25
what do you mean with splice?
dd