I'm trying to build a small flash game, using AS3, where I add mobs to the stage, storing them in an Array for deletion once they've been killed. However I keep getting the following error: TypeError: Error #2007: Parameter child must be non-null.
This is my code currently:
myMobsBuilder();
var mobsArray:Array = new Array();
function myMobsBuilder():void{
for(var i:Number=0; i<3; i++){
this["myMob"+i+":MovieClip"] = new mob();
lvlHolder.addChild(this["myMob"+i]);
myMob.x = 200;
myMob.y = 200;
mobsArray[i] = myMobs;
}
}
Note that I'm trying to dynamically create a variable name for each new instance of the mob. Adding the movie clip of said mob to another movie clip on stage called: lvlHolder, and positioning it. Then adding said movie clip to the Array. This is so that I can delete them both from the array and the stage once a mob has been killed. Unless there's a better way to do it of course. I've researched extensively things like: Dynamically creating variable names, adding and removing movieclips from arrays, and this is the best I can come up with, though I'm fairly new to AS3.
Any help with this would be greatly appreciated.
Ps. The following is the removal code I'm using in another function, but that isn't working so well either:
lvlHolder.removeChild(["myMob"+i]);
mobsArray.splice(i,1);