I'm trying to translate
this script (ActionScript 2) to ActionScript 3 - which, it seems, is quite a mental workout, especially if you don't know much ActionScript to begin with.
Here is what I have so far (slightly modified):
[code]
var tileMap001:Array = new Array();
tileMap001 = [
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 0, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 0, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 101, 101, 101, 101, 101, 101, 101, 101, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
];
var game = {tileW:32, tileH:32};
game.Tile1 = function(){};
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 1;
game.Tile101 = function(){};
game.Tile101.prototype.walkable = true;
game.Tile101.prototype.frame = 101;
var tileSet001:mcTileSet001 = new mcTileSet001();
function buildMap(map:Array, tileSet:MovieClip){
var emptyField:mcEmptyField = new mcEmptyField();
this.addChild(emptyField);
game.clip = this.emptyField;
var mapWidth:Number = map[0].length;
var mapHeight:Number = map.length;
for (var i = 0; i < mapHeight; ++i){
for (var j = 0; j < mapWidth; ++j){
var tileID:String = new String();
tileID = "tile_" + i.toString() + "_" + j.toString();
trace("TileID '" + tileID + "' created."); //for debugging purposes
// ...I've narrowed the problem down to the next 5 lines of code...
// ...everything else works just fine until you remove the comment block from the next line only...
/*game[tileID] = new game["Tile"+map
[j]];
game.clip.addChild(tileSet);
game.clip[tileID].x = (j * game.tileW);
game.clip[tileID].y = (i * game.tileH);
game.clip[tileID].gotoAndStop(game[tileID].frame);*/
}
}
}
buildMap(tileMap001, tileSet001);
stop();
[/code]
If I uncomment just the first line of that block of code, I get an error in the output:
TileID 'tile_0_0' created.
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at flashisogame_fla::MainTimeline/buildMap()
at flashisogame_fla::MainTimeline/frame2()
at flash.display::MovieClip/gotoAndStop()
at flashisogame_fla::MainTimeline/startGame()
Most of what I've translated, I learned all on my own through research and trial and error. It's just that one little block; I wouldn't even know what to search for. I know it works perfectly in AS2, but I'm learning, and I'm trying to keep it current. The ActionScript part of my Flash class only covers the basics.
I'm pretty sure I shouldn't be using "game" or "game.clip" like an array... but I just don't know why, or how it can be fixed.
So, I was wondering if someone could kind of explain to me what is going on there, and toss me a few hints as to how it should be scripted?