EDIT:–Solved–
I’ve begun work on an isometric-tile map editor. I have a really simple problem. Right now it loads with a box and asks for the X: Y: values for how large the map will be. Then it starts off with a multidimensional array filled with 0s based on the user input. Then it makes the map uses MovieClips for each tile, and outputs it. Instead of just outputting it on the stage, I want it to output all the movieClips on another main map movieclip.
Here’s my code:
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class MapAction extends MovieClip {
var mapV:mapSpecs = new mapSpecs;
var errorBox:messBox_mc = new messBox_mc;
var r:int;
var c:int;
var xV:int;
var yV:int;
var mapH:int;
var mapW:int;
var tWidth:int = 64;
var tHeight:int = 32;
var tilesBmp:BitmapData;
var tSheet:BitmapData;
var myParent:Sprite;
var mapArr:Array;
var curMap:Array;
var mcArr:Array;
var mc:tile_mc = new tile_mc();
var mapA:mapArea = new mapArea;
public function MapAction() {
loadSetup();
}
function closeErrorBox(event:MouseEvent) {
removeChild(errorBox);
mapV.startMap.mouseEnabled = true;
}
function loadSetup():void{
addChild(mapV);
mapV.x = 500 - (mapV.width / 2);
mapV.y = 300 - (mapV.height / 2);
mapV.startMap.addEventListener(MouseEvent.CLICK, sM);
}
//on submit
function sM(event:MouseEvent):void{
xV = int(mapV.xValue.text);
yV = int(mapV.yValue.text);
if(xV > 200 || yV > 200 || xV < 1 || yV < 1){
errorBox.messBoxName.text = "Invalid value";
errorBox.messBoxDesc.text = "Your X and Y values must be 1-200";
errorBox.x = 500 - (errorBox.width / 2);
errorBox.y = 300 - (errorBox.height / 2);
addChild(errorBox);
mapV.startMap.mouseEnabled = false;
errorBox.closeBtn.addEventListener(MouseEvent.CLICK, closeErrorBox);
} else {
removeChild(mapV);
gotoMapC(xV, yV);
}
}//On submit
//start map creation
function gotoMapC(r:int, c:int):void{
mapArr = new Array();
for( var i:int = 0; i < c; i++ ) {
mapArr.push( new Array( r ) );
for( var j:int = 0; j < r; j++ ) {
mapArr[ i ][ j ] = 0;
}
}
curMap = mapArr;
mcArr = mapArr;
tSheet = new tileSheet(0,0);
buildMap ();
}//End Map creation
//Start build map
function buildMap():void{
mapW = curMap[0].length;
mapH = curMap.length;
tilesBmp = new BitmapData(64, 32, true, 0x00000000);
for (var yt:int = 0; yt < mapH; yt++) {
for (var xt:int = 0; xt < mapW; xt++) {
var s:int = curMap[ yt ][ xt ];
mcArr[ yt ][ xt ] = new tile_mc;
mcArr[ yt ][ xt ].addEventListener(MouseEvent.MOUSE_OVER, showCoord);
mcArr[ yt ][ xt ].cox = xt;
mcArr[ yt ][ xt ].coy = yt;
drawTile(s, xt, yt);
//addChild(mc);
}
}
}//End Build map
//Start drawTile function
function drawTile (s:Number, xt:int, yt:int):void {
var bmp:BitmapData = getImageFromSheet (s);
var rect:Rectangle = new Rectangle(0, 0, tWidth, tHeight);
//var pt:Point = new Point((((xt * tWidth)-(xt * 32))-(yt * 32))+(mapH * 32), ((yt * tHeight)+(xt * 16))-(yt * 16));
var pt:Point = new Point(0,0);
tilesBmp.copyPixels (bmp, rect, pt);
mcArr[ yt ][ xt ].addChild(new Bitmap(tilesBmp));
addChild(mcArr[ yt ][ xt ]);
mcArr[ yt ][ xt ].x = (((xt * tWidth)-(xt * 32))-(yt * 32))+(mapH * 32);
mcArr[ yt ][ xt ].y = ((yt * tHeight)+(xt * 16))-(yt * 16);
}
//Start getImageFromSheet
function getImageFromSheet (s:Number):BitmapData {
var sheet:BitmapData = tSheet;
//number of columns in tilesheet
var sheetColumns:int = tSheet.width / tWidth;
//position where to take graphics from
var col:int = s % sheetColumns;
var row:int = Math.floor(s / sheetColumns);
//rectangle that defines tile graphics
var rect:Rectangle = new Rectangle(col * tWidth, row * tHeight, tWidth, tHeight);
var pt:Point = new Point(0, 0);
//get the tile graphics from tilesheet
var bmp:BitmapData = new BitmapData(tWidth, tHeight, true, 0x00000000);
bmp.copyPixels (sheet, rect, pt);
return bmp;
}//End GetImageFromSheet
//start show coord
function showCoord(event:MouseEvent):void{
coord.text = "(" + event.target.cox + ", " + event.target.coy + ")";
}//End show coords
}//Class
}//Package
As you can see the main movieClip that I want to put the map on is: var mapA:mapArea = new mapArea; I’ve tried changing some of the addChild’s and putting the refix mapA, with no success. I only get errors saying that a term is undefined. I must be doing something wrong, can anyone help?