A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Odd behavior with modulus

  1. #1
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342

    resolved [RESOLVED] Odd behavior with modulus

    Another thread I will hopefully resolve before someone replies.

    I'm making a picture gallery and putting a bunch of thumbnails in a container.

    Code:
    			for (var i:uint = 0; i < 20; i++)
    			{				
    				var thumbPath:String = variables.folder + "/" + fileArray[i].toString();
    				thumbWidth = (container.width - 48) * 0.20;
    				thumbHeight= (container.height - 10) * 0.25;
    				
    				var thumb:Thumbnail = new Thumbnail(thumbPath, thumbWidth, thumbHeight);
    				thumb.x = ((i % 5) * (thumbWidth + 2)) + 20;
    				thumb.y = (Math.floor(i / 4) * (thumbHeight + 2)) + 2;
    				thumb.name = i.toString();
    				addChild(thumb);
    				
    				thumb.mouseEnabled = true;
    				thumb.mouseChildren = false;
    				thumb.useHandCursor = true;
    				
    				thumb.addEventListener(MouseEvent.CLICK, thumbClick);
    				
    				
    				thumbArray.push(thumb);
    			}
    This is suppose to make 4 rows and 5 columns of thumbnails.

    However, this is where it's acting weird. When I run the script, the pictures should tile like this:

    XXXXX
    XXXXX
    XXXXX
    XXXXX

    (Where each X is a picture)

    But they end up showing like this:

    XXXX_
    XXX_X
    XX_XX
    X_XXX
    _XXXX

    (Where X is a picture and _ is an empty space)

    It doesn't make sense. I don't get it. I had it setup 4 x 4 before and everything showed up properly.

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    And of course I fixed it before anyone answering me lol.

    thumb.y = (Math.floor(i / 4) * (thumbHeight + 2)) + 2;

    Had to read this:

    thumb.y = (Math.floor(i / 5) * (thumbHeight + 2)) + 2;

    I thought I had to put in the number of rows I wanted but really, it was the number of columns.

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