My extremely short minigame has 4 objects on stage, after the game is done, I want them all to be removed from stage and for the game to reinitiate.
I've set it up like this (most bits taken out)
function mainGame():void {
var theCoin:coin = new coin();
var cupOne:cup = new cup();
var cupTwo:cup = new cup();
var cupThree:cup = new cup();
stage.addChild(theCoin);
trace(theCoin.parent);
stage.addChild(cupOne);
trace(cupOne.parent);
stage.addChild(cupTwo);
trace(cupTwo.parent);
stage.addChild(cupThree);
trace(cupThree.parent);
function prepReset():void
{
cupOne.removeEventListener(MouseEvent.CLICK, liftCup1);
cupTwo.removeEventListener(MouseEvent.CLICK, liftCup2);
cupThree.removeEventListener(MouseEvent.CLICK, liftCup3);
stage.addChild(resetBtn);
resetBtn.addEventListener(MouseEvent.CLICK, resetGame);
}
function resetGame(event:MouseEvent):void
{
stage.removeChild(cupOne);
stage.removeChild(cupTwo);
stage.removeChild(cupThree);
letsgoagain();
}
} // end mainGame
function letsgoagain():void
{
stage.removeChild(resetBtn);
mainGame();
trace("RESET")
}
This all works fine the first time around. Once it resets for the second time, i'm getting
Game Started
[object Stage]
[object Stage]
[object Stage]
[object Stage]
RESET
[object Stage]
[object Stage]
[object Stage]
[object Stage]
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Function/coinGame/$construct/mainGame/resetGame()[*\coinGame.as:147]
Cannot display source code at this location.
The parent continues to be the Stage, yet stage.removeChild is not the right syntax? I don't get it. Stackoverflow, would you please kindly point me in the right direction?