// Here is a tile engin I used to create a brick game. Welsh Dragon helped me make it, but maybe you can look at it and it will help you. (This was made in API btw, so its gonna vary a bit)
var tileheight:Number = 20;
var tilewidth:Number = 30;
brickMap = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0], [0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0], [0, 2, 2, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 2, 2, 0]];
brick = createBrick(0x01017E);
brick2 = createBrick(0x0000FF);
drawBricks();
function createBrick(color) {
z == undefined ? z=-1 : 0;
mc = this.createEmptyMovieClip("brick"+z, z--);
with (mc) {
lineStyle(1, 0x000000, 50);
beginFill(color, 100);
moveTo(0, 0);
lineTo(0, tileheight);
lineTo(tilewidth, tileheight);
lineTo(tilewidth, 0);
lineTo(0, 0);
endFill();
}
return mc;
}
function drawBricks() {
for (j=0; j<brickMap.length; j++) {
for (i=0; i<brickMap[0].length; i++) {
if (brickMap[j][i] == 1) {
pos = j*brickMap[0].length+i;
duplicateMovieClip("brick", "brick"+pos, this.getNextHighestDepth());
this["brick"+pos]._x = i*tilewidth;
this["brick"+pos]._y = j*tileheight;
}
if (brickMap[j][i] == 2) {
pos = j*brickMap[0].length+i;
duplicateMovieClip("brick2", "brick"+pos, this.getNextHighestDepth());
this["brick"+pos]._x = i*tilewidth;
this["brick"+pos]._y = j*tileheight;
}
}
}
brick.swapDepths(this.getNextHighestDepth(
));
brick.removeMovieClip();
brick2.swapDepths(this.getNextHighestDepth
());
brick2.removeMovieClip();
}