Posted By

jknight42 on 04/07/10


Tagged

display images Objects grid spacing


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

loric
AndyCatch
thastylos
socialflasher
davidino1978
burnandbass
albertomori


Arrange images (or anything) in a grid


 / Published in: ActionScript 3
 

URL: http://www.cannedbanners.com

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

  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;

Report this snippet  

You need to login to post a comment.