Dynamic Boxes problem

I have two movieclips on _root, one is colorbox and the other is boxoff.

My goal is two create an 8 x 8 grid, with both boxoff and colorbox.

I need colorbox to sit behind the boxoff boxes. So that boxoff is clickable.

I’m having a few problems, first there is no box being shown at position 0, and the second is I can’t get boxoff to display above colorbox.


xgridlines = 9;
ygridlines = 9;
distance = 35;
totalboxes = xgridlines * ygridlines;
setProperty ("boxoff", _visible, false);

k = 0;
for (j=1; j<=xgridlines-1; j++) {
	for (i=1; i<=ygridlines-1; i++) {
		duplicateMovieClip ("boxoff", "boxoff"+k, k);
		duplicateMovieClip ("colorbox", "colorbox"+k, _root.getNextHighestDepth());
		setProperty ("colorbox"+k, _x, distance*i);
		setProperty ("colorbox"+k, _y, distance*j);
		setProperty ("boxoff"+k, _x, distance*i);
		setProperty ("boxoff"+k, _y, distance*j);
		this["color_"+k] = new Color("colorbox"+k);
		iColor = "0xFF0000";
		eval("color_"+k).setRGB(iColor);
		k++;
	}
}

for(var i=0;i<totalboxes;i++){
	_root.attachMovie("boxoff", "boxoff"+i, i);
	_root["boxoff"+i].onRelease = function(){
		trace(this._name);
		//this.removeMovieClip();
	};
}