Skip to main content
Participating Frequently
March 20, 2008
Question

AS3 xml photo gallery

  • March 20, 2008
  • 16 replies
  • 1146 views
I'm fairly new to flash, and after reading a few online tutorials on trying to make xml photo galleries (specifically the one here: http://www.tutorio.com/tutorial/simple-flash-xml-photogallery) I'm trying to figure things out.

I want to make something similar, but have the photos line up in columns (not rows), and once there are a certain number of photos in a column (in this case, 6) have them load into another column.

I have been trying to mess around with the AS given in the tutorial as well as what I've been reading on the net, and here is what I have so far:

***

I'm loading the images and thumbs through the images.xml file. On my stage I only have 2 movie clips (loader & thumbnails) and a dynamic text field (title_txt). Any thoughts??? I really am new to this, but I'm trying hard to figure it out - I'm at the point now where I need help.

Thanks!

Mike (mray@uvic.ca)
***

This topic has been closed for replies.

16 replies

mikey_rayAuthor
Participating Frequently
March 21, 2008
Wow!

Thanks VERY much Jamesabth! That works out BEAUTIFULLY!

All I had to do was go to my stage and delete the loader and thumbnail MCs that I had already created and it works great!

Is there a way to set the registration point of the loader to the middle? The reason I ask is so that when I load a landscape OR a portrait image I want to try to make it load centered - currently they both load with the top left of the image at the "loader.x" and "loader.y" coordinates.

Also, I am currently using the "loader.scaleX" and "loader.scaleY" properties to resize the image, but that always sets it to a fixed percentage of the original image - is there a property that allows you to basically say, "this image can be UP TO but NO MORE than such-and-such high, and such-and-such wide"? (Keeping in mind the possibility of changing the registration point to the middle of the loader.)

I'm SO excited for this new photo gallery! I'm going to spend some time learning all the code in the AS you gave so hopefully I can be of some help to others eventually!

Mike
Participating Frequently
March 21, 2008
Here is the updated code that uses math to scale the image and make the loader align as if its registration point were in the center. If you not sure about what any line of code does - just say and i'll explain as best I can! Hopefully this code works as I haven't tested it either!
Participating Frequently
March 20, 2008
Things you may want to change:

var xspacing:Number = 5;
var yspacing:Number = 5;
var xOffset:Number = 10;
var yOffset:Number = 10;
var thumbWidth:Number = 50;
var thumbHeight:Number = 50;

loader.x = 200; //x Position of large image
loader.y = 10; //y Position of large image

var thumbsPerCol:uint = 6; //Number of icons per column

//---------------------------------

Also note the following if statement:

if(i == numCols - 1) {
thumbsPerCol = images.length() - i*thumbsPerCol;
}

This means that you are not restricted to multiples of 6 images. Without this you would get errors in the last column.
mikey_rayAuthor
Participating Frequently
March 20, 2008
Hi James,

Thanks for the info! The xml file is saved as "images.xml", and the content is:

<gallery>
<image title="Number One" main="(1).jpg" thmb="t(1).gif"/>
<image title="Number Two" main="(2).jpg" thmb="t(2).gif"/>
<image title="Number Three" main="(3).jpg" thmb="t(3).gif"/>
<image title="Number Four" main="(4).jpg" thmb="t(4).gif"/>
<image title="Number Five" main="(5).jpg" thmb="t(5).gif"/>
<image title="Number Six" main="(6).jpg" thmb="t(6).gif"/>
<image title="Number Seven" main="(7).jpg" thmb="t(7).gif"/>
<image title="Number Eight" main="(8).jpg" thmb="t(8).gif"/>
<image title="Number Nine" main="(9).jpg" thmb="t(9).gif"/>
</gallery>

Ultimately I would be having any number of images (I don't know...30 max???) but I want them to appear in columns of 6 (if I make another one, maybe a different number of columns).

Cheers!
Participating Frequently
March 20, 2008
I have not tested this code but hopefully it will work. There are some variables at the top that you will probably want to change, esp. the position of the large image loader.
Participating Frequently
March 20, 2008
If you are prepared to pay, by far the best:

www.lynda.com (you can watch the first few movies of every series for free)

Otherwise:

www.gotoandlearn.com (better when you know a bit more)

or you could ask about concepts here and look in Flash help by pressing F1 when in Flash. (or even email me if you have a quick question - private email: jamesabth@gmail.com)

//-------------------------------------------------------

Could you post the XML file, so that I can see the tag names and post the appropriate AS3 code?
mikey_rayAuthor
Participating Frequently
March 20, 2008
Hmm...shows how new I really am!

I want to do it in AS3 because I figure I'll be doing everything else in it so it would make sense to stay uniform and become good at just one form of coding - what kinds of things (variables, etc) would I need to change to make this AS3?

Is there any tutorials or places you would suggest looking online for this? I have googled, youtubed, and searched everywhere my limited knowledge has allowed me to and I'm still coming up empty handed.

Thanks again.
Participating Frequently
March 20, 2008
This is ActionScript 2, I recommend posting to the AS2 forum.