Hello, I am not an expert by any means. I need help. I am making a photogallery in flash and loading an xml file to bring in the images. I also have a caption loading into a dynamic text box. I would like that caption to link to URL's. I've tried everything but nothing is working. I do have an idea though. I would like to make it so that when the next or the previous button is clicked, the dynamic text box loads a button that links to the URL that applies to the picture that is being displayed at that time. If I you think you can help but I haven't made myself clear, or you have any ideas please respond.
Thanks,
Clay
Hi Clay, I am doing almost the exact thing and what I have works so far. I am adding functionality to it that I haven't figured out but here's what I have so far:
I have an XML file that will serve as a database. I have structured the file as follows:
- <?xml version="1.0" encoding="utf-8" ?>
-
<galleries>
-
<image filename1="bubba.jpg" filename2="me.jpg" template="1" caption1="page one-caption one" caption2="page one-caption two"/>
-
<image filename1="stars.png" filename2="it.jpg" template="2" caption1="page two-caption one" caption2="page two-caption two"/>
-
<image filename1="you.jpg" filename2="her.jpg" template="4" caption1="page three-caption one" caption2="page three-caption two"/>
-
<image filename1="you.jpg" filename2="stars.png" template="5" caption1="page four-caption one" caption2="page four-caption two"/>
-
<image filename1="it.jpg" filename2="her.jpg" template="4" caption1="page five-caption one" caption2="page five-caption two"/>
-
</galleries>
The template part just means what lay-out I am going to use in the flash movie. Sometimes there are two pictures and sometimes one and I am creating templates to use so when the user clicks the next button and the template is "4" it takes the user to the 4th template with the proper images and captions.
In the FLA file, I have an empty movie clips I call image_holder1_mc and image_holder2_mc. I then have dynamic text boxes called caption1_text and caption2_text. Lastly I have my next and previous buttons called next_btn and previous_btn.
The code in the first frame of the flash file is as follows:
- var galleryXML = new XML();
-
galleryXML.ignoreWhite = true;
-
galleryXML.load("gallery.xml");
-
var currentIndex:Number = 0;
-
galleryXML.onLoad = function(success) {
-
if (success) {
-
total = galleryXML.firstChild.childNodes.length;
-
var galleryXML:Array = galleryXML.firstChild.childNodes;
-
//For creating the block-thumbnails to link to the pictures in the gallery
-
for (var i:Number = total; i>0; i--) {
-
myClip.duplicateMovieClip("thumbnail_mc"+i, i, {_x:i*20, _y:i*20});
-
}
-
image_holder1_mc.loadMovie("images/"+galleryXML[currentIndex].attributes.filename1);
-
image_holder1_mc._xscale = 40;
-
image_holder1_mc._yscale = 40;
-
image_holder2_mc.loadMovie("images/"+galleryXML[currentIndex].attributes.filename1);
-
image_holder2_mc._xscale = 40;
-
image_holder2_mc._yscale = 40;
-
caption1_txt.text = galleryXML[currentIndex].attributes.caption1;
-
caption2_txt.text = galleryXML[currentIndex].attributes.caption2;
-
//testing to see if it is grabbing the correct template/scene in the XML file
-
template_txt.text = galleryXML[currentIndex].attributes.template;
-
//testing to see if it is calculating the correct number of entries in the XML file
-
total_txt.text = total;
-
}
-
};
-
listen = new Object();
-
listen.onKeyDown = function() {
-
if (Key.getCode() == Key.LEFT) {
-
prevImage();
-
} else if (Key.getCode() == Key.RIGHT) {
-
nextImage();
-
}
-
};
-
Key.addListener(listen);
-
previous_btn.onRelease = function() {
-
prevImage();
-
};
-
next_btn.onRelease = function() {
-
nextImage();
-
};
-
function nextImage() {
-
if (currentIndex<(total-1)) {
-
currentIndex++;
-
var currentNode = galleryXML.firstChild.childNodes[currentIndex];
-
trace(currentNode);
-
current_pos = currentIndex+1;
-
image_holder1_mc.loadMovie("images/"+currentNode.attributes.filename1);
-
image_holder2_mc.loadMovie("images/"+currentNode.attributes.filename2);
-
caption1_txt.text = currentNode.attributes.caption1;
-
caption2_txt.text = currentNode.attributes.caption2;
-
next_imageNumber();
-
}
-
}
-
function prevImage() {
-
if (currentIndex>0) {
-
currentIndex--;
-
var currentNode = galleryXML.firstChild.childNodes[currentIndex];
-
trace(currentNode);
-
image_holder1_mc.loadMovie("images/"+currentNode.attributes.filename1);
-
image_holder2_mc.loadMovie("images/"+currentNode.attributes.filename2);
-
caption1_txt.text = currentNode.attributes.caption1;
-
caption2_txt.text = currentNode.attributes.caption2;
-
previous_imageNumber();
-
}
-
}
-
function next_imageNumber() {
-
current_pos = currentIndex+1;
-
nextImageOfX.text = current_pos+" / "+total;
-
//caption2_txt.text = current_pos;
-
}
-
function previous_imageNumber() {
-
current_pos = currentIndex+1;
-
nextImageOfX.text = current_pos+" / "+total;
-
}
Hope this helps.
Brent