0

我正在为一个学校项目在 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;

                }

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

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

代码是 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;

        }

和清理:

     function cleanup():void
        {
            removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
            removeEventListener(MouseEvent.MOUSE_DOWN, menuButtonClicked)
            removeEventListener(KeyboardEvent.KEY_DOWN, downKey);
            removeEventListener(KeyboardEvent.KEY_UP, upKey);
            removeEventListener(Event.ENTER_FRAME, loop);
            removeEventListener(Event.ENTER_FRAME, pauseLoop);

            for (var deleteChilds in deleteChildArr){
                removeChild(deleteChildArr[deleteChilds]);
            }

            setToNull();

        }

    }

    function setToNull():void
    {

    myGame=null;

    time=null;

    }

我对此感到有些困惑,试图将所有内容设置为空,但我有一种感觉,它没有发生。有什么想法吗?当您退出最终屏幕时,此代码在某些时候也设置为 null:

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

        playScreen=null;

    }

我希望任何这些都可能导致有价值的答案。我用不同的术语进行了一些谷歌搜索,我发现我的游戏仍然认为有一些电影剪辑需要设置在前面,但是因为它们被设置为空而无法访问?

是否可以像第一次玩一样清除所有内容然后开始新游戏?

4

1 回答 1

0

在删除或更改索引之前,您必须检查孩子现在是否在父母中:

if (this.contains(player))    
    setChildIndex(player,numChildren - 1);
于 2013-01-16T08:16:38.207 回答