[AS2] MovieClips in Arrays and Bitmap Draw Question

Hi, I am working on http://www.student.cs.uwaterloo.ca/~bbobnis/tileshoppro/

I am having difficulty drawing the proper tile on my “workspace” tile. When the application loads it should have a screen of 16x16 green boxes but currently they are blank, or white. Using the same drawing routine I’ve created I am able to select a tile and then draw it when I click on a workspace tile.

var selectedTile;
var terrainTiles = Array();
var newMap:Boolean = true;
var map:Array = Array();
t25 = [25,1,1,1];
map = mapHandle(25, 25, map, t25);
loadImages(tTiles, tPath, fType, "terrainMap", terrainScrollPane);
setupWorkspace(map);
 
function updateCurrentTileBox(tile) {
 var bmp:BitmapData = new BitmapData(16, 16);
 bmp.draw(tile);
 currentTileBox.removeMovieClip(holder);
 currentTileBox.createEmptyMovieClip("holder", currentTileBox.getNextHighestDepth());
 currentTileBox.holder._height = 2;
 currentTileBox.holder._width = 2;
 currentTileBox.holder.attachBitmap(bmp, currentTileBox.getNextHighestDepth());
}
 
function loadImages(imageNum, imageLocation, fileType, Name, scrollPane) {
 var imageList = Array();
 var Name:MovieClip = createEmptyMovieClip(Name, this.getNextHighestDepth());
 var mcLoader:MovieClipLoader = new MovieClipLoader();
 var X=0; // used for positioning
 var Y=1; // used for positioning
 var rows = Math.ceil(imageNum/12);
 mcLoader.addListener(this);
 scrollPane.contentPath = "empty";
 Name = scrollPane.content;
 scrollPane.setStyle("borderStyle", "none");
 Name.attachMovie("white", "spacer", Name.getNextHighestDepth(), {_height: 16*rows}); 
 scrollPane.invalidate();
 for (var i=1; i <= imageNum; i++) {
  imageList.push(imageLocation+i+fileType);
  Name.createEmptyMovieClip(i, i);
  Name*.createEmptyMovieClip("e"+i, i);
  mcLoader.loadClip(imageList[i-1],Name*["e"+i]);
  terrainTiles.push(Name*);
 
  Name*._alpha = 50;
  if (X == 12) X=0;
  if (i > 12*Y) Y++;
  Name*._x = 16*X;
  Name*._y = 16*(Y-1);
  X++;
 
  Name*.onRollOver = function() { this._alpha = 100; }
  Name*.onRollOut = function () { fadeOut(this); }
  Name*.onPress = function () { 
   selectedTile = this; 
   updateCurrentTileBox(this);
   trace(this);
  }
 }
 scrollPane.invalidate();
}
 
function createMap(w, h, tile) {
 var map:Array = Array();
 for (var i = 0; i < h; ++i) {
  map.push(createRow(w, tile));
 }
 return map;
}
 
function createRow(w, tile) {
 var row:Array = Array();
 for (var i = 0; i < w; ++i) {
  row.push(tile);
 }
 return row;
}
 
function mapHandle(w, h, map, default_tile) {
 var newmap:Array = Array();
 var mapW = map[0].length;
 var mapH = map.length;
 if (newMap) {
  newmap = createMap(w, h, default_tile);
  newMap = false;
  return newmap;
 }
 else {
  if (w < mapW) {
   for (var i = 0; i < mapH; ++i) {
    for (var j = 0; j < (mapW - w); ++j) {
     map*.pop();
    }
   }
  }
  if (w > mapW) {
   for (var i = 0; i < mapH; ++i) {
    for (var j = 0; j < (w - mapW); ++j) {
     map*.push(default_tile);
    }
   }
  }
  if (h < mapH) {
   for (var i = 0; i < (mapH - h); ++i) {
    map.pop();
   }
  }
  if (h > mapH) {
   for (var i = 0; i < (h - mapH); ++i) {
     map.push(createRow(w, default_tile));
   }
  }
  return map;
 }
}
 
function drawTerrainTile(target, tile) {
 var bmp:BitmapData = new BitmapData(16, 16);
 bmp.draw(tile);
 target.removeMovieClip(holder);
 target.createEmptyMovieClip("holder", target.getNextHighestDepth());
 target.holder.attachBitmap(bmp, target.getNextHighestDepth()); 
}
 
function setupWorkspace(map) {
 for (var i = 0; i < 25; ++i) {
  for (var j = 0; j < 25; ++j) {
   this.createEmptyMovieClip("x"+i+"y"+j, this.getNextHighestDepth());
 
   worktile = this["x"+i+"y"+j];
 
   worktile._x = workspace._x+j*16;
   worktile._y = workspace._y+i*16;
 
   tileNum = map*[j][0]-1;
   tile = terrainTiles[tileNum];
 
   worktile = worktileFunction(worktile, tile);
   trace(worktile);
  }
 }
}
 
function worktileFunction(worktile, tile) {
 drawTerrainTile(worktile, tile);
 worktile.onPress  = function () {
  drawTerrainTile(this, selectedTile);
 }
 return worktile;
}

I’ve been reading Flash books and researching this problem online. I’m not sure what I’m doing wrong.

Any and all help is much appreciated!

Thanks,
decumbo