Arrange images (or anything) in a grid


/ Published in: ActionScript 3
Save to your folder(s)

This code will arrange any number of images (or display objects) in a grid, you can specify how many columns the grid contains.


Copy this code and paste it in your HTML
  1. // This code should be placed in a for loop of some sort
  2. // that iterates through each of your images or display objects.
  3. //
  4.  
  5. if(iNum==0) {
  6. // place the first image at 0,0
  7. currX = 0;
  8. currY = 0;
  9. } else if(iNum%2 == 0) {
  10. // Change "2" to however many columns this grid should have.
  11. // This runs anytime iNum is evenly divisible by 2
  12. // Which sets currX to 0 and adds another row height to currY
  13. // Essentially starting a new row.
  14. currY += _imageHeight + _imageSpacing;
  15. currX = 0;
  16. } else {
  17. currX += _imageWidth + _imageSpacing;
  18. }
  19. images[i].x = currX;
  20. images[i].y = currY;

URL: http://www.cannedbanners.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.