A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: grid out of duplicateMovieclip?

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    213

    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!

  2. #2
    Getting There! bitsk308's Avatar
    Join Date
    Jul 2000
    Location
    Phoenix, AZ
    Posts
    427
    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

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    213
    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....

  4. #4
    Getting There! bitsk308's Avatar
    Join Date
    Jul 2000
    Location
    Phoenix, AZ
    Posts
    427
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center