AS3 XML Thumbnail Photo Gallery

October 26, 2008 by jared 

Just a basic example of a thumbnail XML driven photo gallery. This version limits the number of thumbnails to the width of the photo, it’s not a perfect solution but at least it’ll get you started somewhere!

Download here.

Comments

23 Responses to “AS3 XML Thumbnail Photo Gallery”

  1. ruben on October 28th, 2008 11:01 pm

    very nice jared. keep them coming!

  2. Johan on December 1st, 2008 1:27 pm

    Very nice indeed, what i would like to see is how you make the thumbnails horisontally scrollable to allow more thumbnails and because it looks good.

  3. johny on February 3rd, 2009 1:57 am

    really nice example jared.

    however, try clicking the second thumbnail. then click the big picture. it will go back to the first image.

  4. jared on February 3rd, 2009 6:10 am

    hi johny thanks for pointing out the bug. I can tell you right now you just need to make a small change in the insertFirstRow function, to the eventlistener.

    im in the midst of cleaning up the whole site, standardizing the code structure. there’ll be an updated version of this, including my personal tween engine, soon…

  5. Gireesh Bhat on March 21st, 2009 9:54 pm

    nice work

  6. G on March 25th, 2009 12:30 am

    How would you make this so the images scaled if they are different sizes? Preferably with a tween:P And add a border around the images that tweens with them.

  7. Brian The Lion on May 4th, 2009 6:31 am

    I need some help resizing the thumbnail to support more then 10 pictures. I found the part in the AS that seems to have the size, but I can’t figure out how to change it.

    Is something like this possible?

    I appreciate it guys!

  8. Brian The Lion on May 4th, 2009 6:51 am

    Well I figured out how to resize the thumbs (just had to re-export it *doh*)

    But as far as adding more thumbs to it, I’m still lost.

  9. Brian The Lion on May 4th, 2009 7:02 am

    alrighty, maybe next time I’ll just play with the code more before asking for help.

    To add more images, you just have to resize the thumbsize (in the MasterThumb.as file) and then set the spacing to the appropriate number (in the Thumbnail.as file).

    Thanks anywho for reading all my posts.

  10. Trish on July 30th, 2009 10:53 am

    Hi Jared,

    I’ve been reading this script and looking at the fla. I cannot figure out how you have connected the AS files to the fla. Also, in the MasterThumb.as there is a typical “over” and “out” for the rollovers of the thumbnails. Where are those timelines? I can’t find any movieclips that have a timeline. I guess I need some help with the mysteries of as files. Thanks for your time and thank you for the script!

  11. Trish on August 20th, 2009 3:19 pm

    Hi Jared,

    I figured out the “over” and “out” LOL. Now I am trying to add a title to each image via the xml. I’ve tried numerous angles but nothing is working. Can you help?

    Thanks for the code!

  12. Trish on August 25th, 2009 5:08 pm

    Hi Jared,

    I still cannot add text to this slide show. I’ve tried everything I can think of. Will send money for help!!!!! Let me know how much and I’ll put it in the “donate” box. Thanks!

  13. alex on September 8th, 2009 1:12 am

    this is very strange

    why is that when you click on the big pic the the first image reloads ??

    i mean why is the big pic clickable in the first place

    nice work by the way
    very minimalistic

  14. Jason Cavitt on October 18th, 2009 3:14 am

    how would I add a second row of thumbnails if there were more than 10 images?

  15. simone on January 22nd, 2010 2:25 pm

    excellent work, jared…

    I added Key navigation (LeftArrow and RightArrow) by simply inserting into Thumbnail class:

    import flash.events.*;
    import flash.display.Sprite;

    private var pressedKeys:Object = {};
    private var graphicsArray:Array = new Array;

    —–

    into init() function:
    stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
    stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );

    ——

    into insertFirstRow() function:

    graphicsArray[i] = thumb;

    ——-

    and finally adding these 3 functions:

    private function keyDownHandler( e:KeyboardEvent ):void
    {
    if( pressedKeys[ e.keyCode ] )
    {
    return;
    }

    pressedKeys[ e.keyCode ] = 1;
    traceEvent( e );
    }

    private function keyUpHandler( e:KeyboardEvent ):void
    {
    delete pressedKeys[ e.keyCode ];
    }

    private function traceEvent( e:KeyboardEvent ):void
    {
    if (e.keyCode==39) {
    if (currentPhoto0) {
    graphicsArray[currentPhoto-1].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    }
    }
    }

  16. simone on January 22nd, 2010 2:28 pm

    sorry, the last function has been cut by the box length:

    private function traceEvent( e:KeyboardEvent ):void
    {
    if (e.keyCode==39) {
    if (currentPhoto0) {
    graphicsArray[currentPhoto-1].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    }
    }
    }

  17. nayamoshi on January 29th, 2010 10:02 am

    how can i scroll the thumbnails?

  18. matt on May 6th, 2010 3:18 pm

    hi. i cant seem to find where to the colour margin round the thumbnails is set. any ideas?

    thanks

  19. Ben on May 7th, 2010 7:53 pm

    How would I implement this so it only runs on a particular frame in my .fla file?

    Thanks!

  20. jared on May 8th, 2010 5:59 am

    try using use the Loader() Class to load the swf

  21. jared on May 8th, 2010 6:00 am

    Look in the library, there’s an exported movieclip

  22. Ben on June 10th, 2010 3:03 pm

    I noticed in the Thumbnail class that we are only inserting one row. Ive had a hard time figuring out how to add a second or even third row of thumbails that can be loaded when clicked on. Any help?

    Thanks!

  23. Ben Cheah on July 8th, 2010 4:23 am

    Thanks Jared, Just what I was looking for.

    Simone, I made some changes to your code for the keyboard event. Your traceEvent function wasn’t quite working for me:

    private function traceEvent( e:KeyboardEvent ):void {
    if (e.keyCode == 37)
    {
    graphicsArray[currentPhoto - 1].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    if (currentPhoto == 0)
    {
    graphicsArray[currentPhoto + 9].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    }
    }
    if (e.keyCode == 39)
    {
    graphicsArray[currentPhoto + 1].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    if (currentPhoto == 9)
    {
    graphicsArray[currentPhoto - 9].dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));
    }
    }
    }

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!