Actionscript 3 我重新启动游戏的代码出了什么问题

Actionscript 3 我重新启动游戏的代码出了什么问题,actionscript-3,restart,Actionscript 3,Restart,我正在为一个学校项目在AS3中制作一个游戏,我一直在重启游戏。游戏结束后,会出现最后一个屏幕,然后您可以返回菜单。这一切进展顺利,但当我再次尝试玩时,它会说: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/setChildIndex() at MethodInfo-277() 我对此进行了

我正在为一个学校项目在AS3中制作一个游戏,我一直在重启游戏。游戏结束后,会出现最后一个屏幕,然后您可以返回菜单。这一切进展顺利,但当我再次尝试玩时,它会说:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/setChildIndex()
at MethodInfo-277()
我对此进行了调试,接下来是下一段代码:

               if (bringToFront==1){

                    setChildIndex(player,numChildren - 1);
                    setChildIndex(foppeLeft, numChildren - 1);
                    setChildIndex(foppeIdle, numChildren - 1);
                    setChildIndex(foppeRight, numChildren - 1);
                    setChildIndex(foppeDown, numChildren - 1);
                    setChildIndex(foppeUp, numChildren - 1);
                    setChildIndex(foppeTalent, numChildren - 1);
                    setChildIndex(abeIdle, numChildren - 1);
                    setChildIndex(abeUp, numChildren - 1);
                    setChildIndex(abeDown, numChildren - 1);
                    setChildIndex(abeLeft, numChildren - 1);
                    setChildIndex(abeRight, numChildren - 1);
                    setChildIndex(abeSkateIdle, numChildren -1);
                    setChildIndex(abeSkateUp, numChildren - 1);
                    setChildIndex(abeSkateDown, numChildren - 1);
                    setChildIndex(abeSkateLeft, numChildren - 1);
                    setChildIndex(abeSkateRight, numChildren - 1);
                    setChildIndex(abeSkateOn, numChildren-  1);
                    setChildIndex(abeSkateOff, numChildren - 1);
                    setChildIndex(marcoIdle, numChildren - 1);
                    setChildIndex(marcoDown, numChildren - 1);
                    setChildIndex(marcoUp, numChildren - 1);
                    setChildIndex(marcoLeft, numChildren - 1);
                    setChildIndex(marcoRight, numChildren - 1);
                    setChildIndex(marcoJumpUp, numChildren - 1);
                    setChildIndex(marcoJumpIdle, numChildren - 1);
                    setChildIndex(marcoJumpDown, numChildren - 1);
                    setChildIndex(marcoJumpRight, numChildren - 1);
                    setChildIndex(marcoJumpLeft,numChildren - 1);
                    setChildIndex(hudIngame,numChildren - 1);
                    setChildIndex(time,numChildren - 1);
                    setChildIndex(c1000PuP, numChildren - 1);
                    setChildIndex(univePuP, numChildren - 1);
                    setChildIndex(rabobankPuP, numChildren - 1);
                    setChildIndex(frieslandPuP, numChildren - 1);
                    setChildIndex(jakoPuP, numChildren - 1);

                    bringToFront=0;

                }
通过删除所有这些,它确实不再给出错误,但在我的游戏中,我通过
tileSheet
和一个数组构建了关卡。当我进入下一级时,它不会加载瓷砖;它显示第一个级别,但代码适用于第二个级别

(请原谅我的混乱代码,我是新手。)

代码有2000多行,所以我不会发布,但我会发布一些可能会稍微澄清一下的内容

当您到达终点时,会发生以下情况:

        for (var mapEnd in mapsEndArr){
            if (player.hitTestObject(mapsEndArr[mapEnd])){
                if (oneRound==0){
                oneRound=1;
                player.x=0;
                }
            }
        }

        if (oneRound==1){
            //Making sure the arrows & pick up points get deleted when going to another map.

            if (foppeAction == true){

                for (var drawClueEnd in clueArray){
                    removeChild( clueArray[drawClueEnd] );
                }

                if (c1000PuPDrawn==true){
                    c1000PuP.visible=false;
                }

                if (univePuPDrawn==true){
                    univePuP.visible=false;
                }

                if (rabobankPuPDrawn==true){
                    rabobankPuP.visible=false;
                }

                if (frieslandPuPDrawn==true){
                    frieslandPuP.visible=false;
                }

                if (jakoPuPDrawn==true){
                    jakoPuP.visible=false;
                }
                foppeAction = false;
                freeze=0;

            }
            mapNumberY=0;
            mapNumberX=0;   

            mapsUpArr.splice(0, mapsUpArr.length);
            mapsDownArr.splice(0, mapsDownArr.length);
            mapsLeftArr.splice(0, mapsLeftArr.length);
            mapsRightArr.splice(0, mapsRightArr.length);
            wallArrayS.splice(0, wallArrayS.length);
            wallArray.splice(0, wallArray.length);
            iceArray.splice(0, iceArray.length);
            iceBorderArray.splice(0, iceBorderArray.length);
            clueArray.splice(0, clueArray.length);
            pickUpPoint.splice(0, pickUpPoint.length);

            c1000PuPDrawn=false;
            univePuPDrawn=false;
            rabobankPuPDrawn=false;
            frieslandPuPDrawn=false;
            jakoPuPDrawn=false;

            hudBars = new HudBars();
            hudBars.x = 0;
            hudBars.y = 0;
            addChild(hudBars);

            dispatchEvent( new NavigationEvent( NavigationEvent.FINAL ) );

            if (points==0){
                DocumentClass.endScreen.pointsText.text=("Je hebt geen logo's verzamelt.");
            }

            if (points>0 && points<5){
                DocumentClass.endScreen.pointsText.text=("Je hebt "+ points.toString() +"logo('s) verzamelt.");
            }

            if (points==5){
                DocumentClass.endScreen.pointsText.text=("Je hebt alle logo's verzamelt!");
            }

            points=0;

            //Removing all the childs and eventlisteners to clean stuff up in the cleanup function.
            cleanup();

            oneRound=2;

        }
我对它有点困惑,试图把所有的东西都设置为空,但我感觉在某个地方它没有发生。有什么想法吗?当您退出最终屏幕时,此代码也会在某个点设置为null:

    public function finalScreen():void
    {
        endScreen = new EndScreen();
        endScreen.addEventListener( NavigationEvent.MENU, onRequestMenu );
        endScreen.x = 0;
        endScreen.y = 0;
        addChild(endScreen);

        playScreen=null;

    }
我希望所有这些都能带来一个有价值的答案。我用不同的术语在谷歌上搜索了一下,我发现我的游戏不知怎么的仍然认为有一些电影嘴唇需要放在最前面,但是因为它们被设置为空,所以无法找到它们


有没有可能像你第一次玩的那样,把所有的东西都清除,然后开始一个新游戏

在删除或更改索引之前,必须先检查父级中是否有子级:

if (this.contains(player))    
    setChildIndex(player,numChildren - 1);

也许可以将oneRound变量设置为0而不是null,或者尝试将一些其他变量设置为0而不是null。如果您在大列表中指出,如果删除它,它会工作。如果你删除其中的一些呢?你能专注于它正在破坏的一件事吗?检查你是否没有对第一个引用代码块中提到的任何资产调用
removeChild
。另外,如果您只需切换可见性,为什么还要设置子索引?对于数组的清理,只需将其长度设置为0,不需要拼接id。只需array.length=0?哇,我不知道。非常感谢。我仔细地检查了我应该移除哪些,哪些不适合孩子们。就是这样。不,真正的问题是“地图生成器”。我得到了一个tilesheet,它可以在你每次离开屏幕时重建一个地图(mapX为左和右加上+1或-1,mapY为上和下加上+1或-1),这样效果很好,但问题是;游戏重新启动后它不会更新。还有@NathanielFord,试过了。但它对列表中的每一个setChildIndex都这样做。。。另外,有些是静态的,有些是公共的。哦,我没有将任何变量设置为null。。只是一些movieclips,这样代码就不会工作了,也不会再重复了。太棒了,我想应该可以了,但是我得到了以下错误:TypeError:error#1006:contains不是一个函数。在MethodInfo-283()中,是否可以使用:if(player!==null)?您可以进行如下检查:if(player&&player.parent&&player.contains(player))
if (this.contains(player))    
    setChildIndex(player,numChildren - 1);