Grid arrangement

Code Actionscript 2.0

Frame action

i = 1;
for (gx = 1; gx < 9; gx = gx + 1) {
for (gy = 1; gy < 9; gy = gy + 1) {
i = i + 1;
square0.duplicateMovieClip("square" + i, i);
this["square" + i]._width = 25;
this["square" + i]._height = 25;
this["square" + i]._x = 20 + gx * 40;
this["square" + i]._y = 20 + gy * 40;
}
}
square0._visible = 0;
// hide original, only work with copies

Code Actionscript 3.0

var i=1; var Squares: Array = new Array(); var gx = 1; var gy = 1; square0.visible = false; for (gx = 1; gx < 9; gx = gx + 1) { for (gy = 1; gy < 9; gy = gy + 1) { i = i + 1; //important: square has to be exported for actionscript //go to "linkage" in library menu Squares[i] = new squareObject(); Squares[i].width = 25; Squares[i].height = 25; Squares[i].x = 20 + gx * 40; Squares[i].y = 20 + gy * 40; addChild(Squares[i]); } }

Description

This script generates a grid arrangement, with the help of two nested for-loops, which sets the horizontal and vertical position. The variable i is used as a sequence number for the multiple instances. The variables gx and gy run through the values 1 to 9 several times, so they can not be used to assign unique identities to each instance.

Download

Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File


Share