Question
Help with syntax
Hello,
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.
Evrard
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.
Evrard