2 Replies Latest reply on May 20, 2006 7:53 AM by Husain

    Duplicating MovieClips into Rows & Columns

    Husain
      Hi People,

      I am creating a project, which is a dynamic image gallery, wherein the images are loaded from an XML file. I am looking to create the thumbnails as rows & columns, based on the total number of images.

      I am able to duplicate the movieclips in rows & columns, if I define the number of rows & columns, but don't know how to do this at runtime, depending on the total number of images.

      Let's say I have 12 images, so the resulting grid should be like the one shown below:

      * * * * *
      * * * * *
      * *

      Can anybody please help, this is really urgent, and I losing my head over this

      Thanks to all in advance.

      Cheers,
      Husain
        • 1. Re: Duplicating MovieClips into Rows & Columns
          Level 7
          //upper left corner of image grid
          var colStart = 30;
          var rowStart = 30;

          var imagesPerColumn = 5;
          var colCount = 0;

          //width and height of thumbs plus any buffer space between them
          var colWide = 50;
          var rowHigh = 50;

          //starting depth of new clips
          var deep = 5;

          for (var i = 0; i < 12; i++) {
          thisImage = this.attachMovie("thumb", "thumb" + i, deep + i, {_x:colStart +
          (colCount * colWidth), _y:rowStart});
          colCount++;
          if (colCount + 1 > imagesPerColumn) {
          colCount = 0;
          rowStart += rowHigh;
          }
          }


          This should get you going - just replace the 12 in the for loop with your
          array length. I used attachMovie to attach a thumb clip from the library but
          you can duplicate instead.

          HTH, let me know if you need more explanation.


          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          www.macromedia.com/support/forums/team_macromedia/


          • 2. Re: Duplicating MovieClips into Rows &amp; Columns
            Husain Level 1
            Hi Dave,

            Thanks a ton for this, it works just perfectly! But I still need to understand the idea/logic behind this, especially the actions in the 'for loop'. If you can throw in some theory on this, it would be just awesome.

            Cheers,
            Husain