I'm having this error in which I have a Main Menu scene, an Options scene, and a game scene. I have a external file which holds all the public variables that I need between scenes. In the game, there is a picture of water in the background which is purely decorative and doesn't do anything, the only time I use it in code is when I'm moving it to the back so other platforms can be positioned on top of it by using the code:
setChildIndex(gfxWater, 1);
This used to work before I put the options scene in, and still does, provided I don't go to the options scene. Even if I don't touch anything on the options scene, simply going there causes this line to throw a "Parameter Child must be non-null" error. I tried to trace gfxWater right beforehand, but just got null. I simply dragged the water onto the screen to create it and gave it the instance name gfxWater. I don't understand how that could be null, its still there even when this line breaks, it's just on top of everything else.
In the options menu I am not doing anything with the water, I'm only changing variables such as whether or not to play music or sound effects, stuff like that. Nothing relative to the water. The only thing that I can think of that might be causing a problem is that I used a custom font in the options scene, so I had to create the text in AS3. Before I transition back to the main menu though, I make sure to remove the text. That code is here:
//This Removes The Text
for (m = 0; m < optionsTextArray.length; m++){
optionsTextArray[m].parent.removeChild(optionsTextArray[m]);
}
optionsTextArray.splice(0, optionsTextArray);
//This Hides The Images
soundFxCheck.parent.removeChild(soundFxCheck);
soundFxX.parent.removeChild(soundFxX);
musicCheck.parent.removeChild(musicCheck);
musicX.parent.removeChild(musicX);
codeCheck.parent.removeChild(codeCheck);
codeX.parent.removeChild(codeX);
//This Transitions To The Main Menu
gotoAndPlay("menuStart", "Main_Menu");
Any help with this issue would be greatly appreciated. Also just for reference I am using AS3 on CS3 (Sorry, my school is a little out of date). Thanks in advance开发者_StackOverflow中文版!
This is an error you'll get if you effectively try to do this:
removeChild(null);
Which means that one of the properties you're parsing through removeChild()
doesn't have a value.
Because you haven't supplied any code that shows how your objects are being added and so on, it's hard to determine where exactly in the application your issue is; everything I see above seems OK to me.
Instead of dragging it from the library why not add it with code? That way you know it exists the the right scope.
You'll need to go into the properties of the waterfall movieclip in the library and set it to Export for Actionscript, and assign it a name (lets assume WaterFall). Then:
var waterfall:WaterFall = new WaterFall();
this.addChildAt(waterfall,0);
Now you shouldn't need to adjust its depth again because it is on the bottom depth and any other objects will be added above it, unless they specifically target depth 0 themselves.
精彩评论