2 Replies Latest reply on Apr 30, 2007 3:56 AM by evrardBlom

    Help with syntax


      I am trying to read some professional codes but i always stumble on some syntaxes that send me back to actionscript school. Here is one case:

      // Definition of an object

      1- var game:Object = new Object();
      2- game.Columns = 10;
      3- game.rows = 10;
      4- game.spacing = 30;
      5- game.depth = 1000;
      6- game.path = this.grid;
      7- game.numberOfTypes = 8;

      // Next, a function called buildGrid() is defined.
      8- function buildgrid(){
      9- for (var j:Number = 0; j 10- for (var i:Number = 0; i 11- var name:String = "cell"+i+"_"+j;
      12- var x:Number = i*game.spacing;
      13- var y:Number = j*game.spacing;
      14- var type:Number = 1;
      15 - game.path.attachMovie("cell", name, ++game.depth);
      16- game.path[name]._x = x;
      17- game.path[name]._y = y;
      18- game[name] = {x:i, y:j, name:name, type:type,
      19- clip:game.path[name]};
      20- }
      21- }
      22- }

      Ok, i understand the first first defined an object (line 1 thru 7), then he used the custom properties in there to store values that he used in the function buildGrid defined in line 8 thru 22.

      My problem is the lines 18 and 19. In the book he explains this is an object that is created to store information about the "cell" created after each loop cycle. To be frank with you i dont understand this syntaxe at all. Question:

      - Because game[name] is named after the game object introduced in line 1 i would expect them to hold values of the variables introduced in line 2 to 7, well, i see different new ones. What is the relation betwen game[name] and the game object itself then? Could it been named otherwise?

      Thanks for helping.

        • 1. Re: Help with syntax
          Devdoc Level 1

          game[name] is in fact a variable property of the game object. Seeing how he sets the variable name to

          name:String = "cell"+i+"_"+j;

          it should evaluate to something like game.cell1_2 (the numbers being dependent on how far along the two for loops we are).

          So he creates a whole bunch of objects under the game object and give them properties (x:i, y:j and so on). So we get something like: game.cell1_2.x = 1. And he also gives the object a reference to a clip:


          My guess is this code is for populating the game object with custom movieclip, like tiles in a background or enemies.

          Good luck programing!
          • 2. Re: Help with syntax
            evrardBlom Level 1
            "My guess is this code is for populating the game object with custom movieclip, like tiles in a background or enemies"

            Right this code is from the chapter 7 (about Tiles) of the book " flash MX 2004 game design demystified " by Jobe Makar. It is the official guide to creating games with the software.