Author Topic: Would anyone be willing to help me with some Actionscript?  (Read 368 times)  Share 

Nine Toes

  • Thorry, I didn't mean to thpit all over you!
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
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?
Watch, I just killed this topic...

fred

  • Egad, Trixie, the water can speak!
    • I can help with play testing
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
I made it work in AS3 like this, slightly optimized in places:

[code]
stop();

var tileW:uint = 32;
var tileH:uint = 32;
var tileSet001:String = "mcTileSet001";
var tileMap001:Array = [
   [  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]
   ];

function buildMap(map:Array, tileSet:String){
   var emptyField:mcEmptyField = new mcEmptyField();
   this.addChild(emptyField);
   var mapWidth:uint = map[0].length;
   var mapHeight:uint = map.length;
   for (var i:uint = 0; i < mapHeight; ++i){
      for (var j:uint = 0; j < mapWidth; ++j){         
         var ClassReference:Class = getDefinitionByName(tileSet) as Class;
                    var t = new ClassReference();
         if (tileMap001[j] == 0){
            t.walkable = false;
            t.defaultFrame = 1;
         } else {
            t.walkable = true;
            t.defaultFrame = 10;
         }
         t.x = j * tileW;
         t.y = i * tileH;
         t.uniqueID = (i*tileH)+j;
                        t.uniqueIDString = "tile_" + i + "_" + j;
         trace (t.uniqueIDString);//debug trace
         t.gotoAndStop(t.defaultFrame);
         emptyField.addChild(t);
      }
   }
};

buildMap(tileMap001, tileSet001);
[/code]