movieClip in Array displays null, and aren't showing up on stage.addChild(Array[i])
- by jtdino
i am new to Actionscript3, i need to know why i keep getting Parameter child must be non-null. And my code won't display 5 enemyBlock objects onto the stage but only just one.
any tips and help will be much appreciated. thanks in advance.
returns:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at flash.display::Stage/addChild()
at BlockDrop_fla::MainTimeline/EnemyBlockPos()
at BlockDrop_fla::MainTimeline/frame2()
// declare varibles
var isEnemyMoving:Boolean = false;
var enemyArray:Array;
var enemyBlock:MovieClip = new EnemyBlock(); // assign EnemyBlock class to enemyBlock
var enemyBlockMC:MovieClip;
var count:int = 5;
var mapWidth:Number = 800;
var mapHeight:Number = 600;
function EnemyBlockPos() :void {
// assign new MovieClip not null
enemyBlockMC = new MovieClip;
enemyArray = new Array();
for(var i=1; i<= count; i++){
// add class to MC
enemyBlockMC.addChild(enemyBlock);
// randomize position
enemyBlock.x = Math.round(Math.random()*mapWidth);
enemyBlock.y = Math.round(Math.random()*mapHeight);
// set motion
enemyBlock.movement = 5;
// add MC to array
enemyArray.push(enemyBlockMC);
}
for (var w = 1; w <= enemyArray.length; w++) {
addChild(enemyArray[w]);
}
} // endOf EnemyBlockPos