我正在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;
}
和清理:
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,但我感觉某处它没有发生。有什么想法吗?此代码在某些时候也设置为null,当您退出最终屏幕时就在这里:
public function finalScreen():void
{
endScreen = new EndScreen();
endScreen.addEventListener( NavigationEvent.MENU, onRequestMenu );
endScreen.x = 0;
endScreen.y = 0;
addChild(endScreen);
playScreen=null;
}
我希望这一切都可能带来有价值的答案。我用不同的术语做了一些谷歌搜索,我发现我的游戏仍然认为有那些需要设置在前面的动画片段,但是因为它们被设置为空而无法到达?
是否可以清除所有内容,然后像第一次玩的那样开始新游戏?
答案 0 :(得分:0)
在删除或更改索引之前,您必须检查孩子是否在父母中:
if (this.contains(player))
setChildIndex(player,numChildren - 1);