# Adding Links to XML photo gallery

**URL:** https://forum.kirupa.com/t/adding-links-to-xml-photo-gallery/185930
**Category:** flash
**Created:** [April 17, 2006, 7:46pm UTC](https://forum.kirupa.com/t/adding-links-to-xml-photo-gallery/185930 "2006-04-17T19:46:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![stewdawg35](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@stewdawg35](https://forum.kirupa.com/u/stewdawg35)
#### Post date: [April 17, 2006, 7:46pm UTC](https://forum.kirupa.com/t/adding-links-to-xml-photo-gallery/185930/1 "2006-04-17T19:46:00Z")

</div>

I am playing with the xml [photo gallery tutorial](http://kirupa.com/developer/mx2004/xml_flash_photogallery.htm) and wanted to add the ability for users to click on a particular image and have it go to its own url.

This is what I have done so far:

in images.xml I have added a \<link\> child on the same node or level as \<image\> and \<caption\>

images.xml i.e.

```auto

<images>
    <pic>
        <image>image1.jpg</image>
        <caption>Hello World</caption>
        <link>http://www.google.com</link>
    </pic>
</images>

```

Then in the flash file xml\_pg\_final.fla I added the following action script:

```auto

function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        image = [];
        description = [];
        [COLOR=Red]link = [];[/COLOR]
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
            description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
            [COLOR=Red]link* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;[/COLOR]
        }
        firstImage();
    } else {
        content = "file not loaded!";
    }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");
/////////////////////////////////////
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();
};
/////////////////////////////////////
p = 0;
this.onEnterFrame = function() {
    filesize = picture.getBytesTotal();
    loaded = picture.getBytesLoaded();
    preloader._visible = true;
    if (loaded != filesize) {
        preloader.preload_bar._xscale = 100*loaded/filesize;
    } else {
        preloader._visible = false;
        if (picture._alpha<100) {
            picture._alpha += 10;
        }
    }
};
function nextImage() {
    if (p<(total-1)) {
        p++;
        if (loaded == filesize) {
            picture._alpha = 0;
            picture.loadMovie(image[p], 1);
            desc_txt.text = description[p];
           [COLOR=Red] link.loadMovie(link[p], 1);[/COLOR]
            picture_num();
        }
    }
}
function prevImage() {
    if (p>0) {
        p--;
        picture._alpha = 0;
        picture.loadMovie(image[p], 1);
        desc_txt.text = description[p];
        [COLOR=Red]link.loadMovie(link[p], 1);[/COLOR]
        picture_num();
    }
}
function firstImage() {
    if (loaded == filesize) {
        picture._alpha = 0;
        picture.loadMovie(image[0], 1);
        desc_txt.text = description[0];
        [COLOR=Red]link.loadMovie(link[0], 1);[/COLOR]
        picture_num();
    }
}
function picture_num() {
    current_pos = p+1;
    pos_txt.text = current_pos+" / "+total;
}

```

It obviously does not work (the rest of the gallery does though) I created a dynamic movie clip and labeled it “link” and placed it on the stage as a bg element however I am pretty sure this is the wrong way to hyperlink the images and description. I am new to AS and would appreciate any direction or advice.  
Ideally I would like to link the image and caption but if I can at least get one of them to work I would be estatic.

Thanks…
