A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: using modulus to loop thumbnails

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    4

    Question using modulus to loop thumbnails

    I'm still pretty novice when it comes to as3 and am trying to use modulus to loop 14 thumbnails in an array.

    i have a property called firstThumb that keeps track of the first thumbnail being displayed and a forward and back function that looks like this

    PHP Code:
    private function reverseThumbs(e:MouseEvent):void
            
    {
                
    trace("moving back");
                
    displayThumbs(firstThumb-1DISPLAYED);
                
                
    //update our pointer to the first thumb to display
                
                
                
    firstThumb--;
                
        } 
    PHP Code:
    private function advanceThumbs(e:MouseEvent):void
            
    {
                
    trace("moving forward");
                
    displayThumbs(firstThumb+1DISPLAYED);;
                
                
    //update our pointer to the first thumb to display
                
                
                
    firstThumb++;
                
                
            } 

    i also have a position counter to keep track of the thumbnails being displayed
    PHP Code:
    //display some of the thumbs in the thumbarray
            
    private function displayThumbs (aStart,howMany:int):void
            
    {
                
                
    //13%14 modulus 
                //get rid any thumbs already displayed
                
    for (var firstThumbfirstThumb+DISPLAYEDn++) 
                {
                    
                    
                    
    //remove the thumb if it is in the displaylist
                    
    if (this.contains(thumbArray[n])) removeChild(thumbArray[n]);
                    
                }
                
                
    //then display the current four
                
    var posCounter:int =0;
                for (var 
    aStartaStart+howManyi++)
                
                {
                    
    addChildthumbArray[i] );
                    
    thumbArray[i].45;
                    
    thumbArray[i].150 +posCounter*(thumbArray[i].width MARGIN);
                    
    posCounter++;
                }
                
            } 
    if anyone has any suggestions for how i can go about using modulus to loop the images through, itd be great
    Last edited by tonyxspote; 04-07-2009 at 04:01 PM.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    This looks like you have one row of images and you want to use mod to loop between the last image and the first image right? (As opposed to making a grid and using mod to determine which row).

    If that's the case you can just use [i % thumbArray.length].

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    where would i put that in at?

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Use that in the last 4 lines of your displayThumbs function.

  5. #5
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    just replace [i] with [i % thumbArray.length]?

  6. #6
    Junior Member
    Join Date
    Apr 2009
    Posts
    4
    i dont think that the [i%thumbArray.length] is the solution
    Last edited by tonyxspote; 04-07-2009 at 06:35 PM.

Tags for this Thread

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