1 Attachment(s)
Image Slicing and tile replacement
Hello all.
I'm a bit of a weekend warrior when it comes to flash, so bear with me.
Basically, I'm writing an application to be used for Dungeons and Dragons. The idea is to replace traditional battle-mats and markers with a laptop and projector. Now, to the problem.
I'm using Filippo Lughi's method of slicing up a tileset image (http://www.flepstudio.org/forum/tuto...ipt-3-0-a.html -- great tutorial), placing individual tiles into an array, reading an array from a text file, then placing tiles from the tiles array on the stage corresponding the text file. Here's the troublesome bit of code.
Code:
var tilenum:int=0;
for (var k=0;k<currentMapArray.length;k++) {
for (var l=0;l<currentMapArray[k].length;l++) {
tilenum=currentMapArray[k][l];
var tileToAdd:MovieClip = new MovieClip();
tileToAdd = clips_array[tilenum];
addChild(tileToAdd);
tileToAdd.name = "tile-"+l+"-"+k;
tileToAdd.width=gridSize;
tileToAdd.height=gridSize;
tileToAdd.x = gridSize*l;
tileToAdd.y = gridSize*k;
trace(tileToAdd.name);
}
}
When the code is run, all of the tile names are traced, but only two tiles end up on the stage. The two that make it onto the stage are the last instances of each type of tile (image attached). It seems like each run through the loop replaces the previously placed tile if it's the same type. Does anyone have an idea why this is happening? No errors are thrown during compiling. When I check Objects, there are only two tile clips listed-- the two on the stage.
Any insight would be greatly appreciated. I can post the rest of the code if necessary. Thanks!
-Hero