-
grid out of duplicateMovieclip?
peepz,
i have a small piece of code within i want to build a grid. The grid will be dynamicly builded out of 4 columns (Max) and the rows are dependig of the "ap.length". Can somebody build this within my code?:
code:
for (var z = 0; z<ap.length; z++)
{
duplicateMovieClip(mcPhotoHolder, "mcPhotoHolder"+z, z);
this["mcPhotoHolder"+z]._y = 136*z
}
thanks already peepz!
-
Getting There!
This should do it. The rowCount variable is just a counter that's incremented each time you get to the end of a row. The % operator gets the remainder of the current z value divided by 4. This way you get a repeating 1-4 cycle. The z+4 is there to simplify the math for the first iteration (z = 0 thru 3). The switch then places the x depending on what "column" its in. You can change the two 4's in the switch declaration to anything you like to get a grid as wide as you want.
code: var ap:Array = new Array(17);
var rowCount = 0;
for (var z = 0; z<ap.length; z++) {
duplicateMovieClip(mcPhotoHolder, "mcPhotoHolder"+z, z);
this["mcPhotoHolder"+z]._y = 100+(25*rowCount);
switch((z+4)%4){
case 0:
trace("col 1");
this["mcPhotoHolder"+z]._x = 100;
break;
case 1:
trace("col 2");
this["mcPhotoHolder"+z]._x = 125;
break;
case 2:
trace("col 3");
this["mcPhotoHolder"+z]._x = 150;
break;
case 3:
trace("col 4");
this["mcPhotoHolder"+z]._x = 175;
rowCount ++;
break;
}
}
_b
-
thanks for yur fast reply, i dont 't get it exactly and i tried it but he wat start duplicating anymore...
don't get the "case:" thing....
-
Getting There!
switch / case is more efficient version of if/else if you're going to have multiple else's. It evaluates the expression in the switch parameter, then the case's are the possible results of the evaluation.
Post your .fla and I'll try to see why it isn't integrating.
_b
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|