...

View Full Version : Loading different link to a getURL



crays
12-07-2008, 05:15 PM
Hi, i'm using a XML and flash photogallery as in this tutorial http://www.kirupa.com/developer/mx2004/xml_flash_photogallery9.htm . But i would like to link to a site for each different picture. How should i do this ? in the main frame i used for displaying picture, i added a get URL script but i don't know how i should change the link for each different picture.

gnomeontherun
12-09-2008, 11:50 PM
You will need to have your XML file add some data. So you need a child node for the URL.

Example (taken from the site)

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
<pic>
<image>http://www.kirupa.com/developer/mx2004/pg/structure.jpg</image>
<caption>Structure</caption>
<location>http://www.kirupa.com</location>
</pic>
</images>

Then your loader must grab the new node and put it in an array like the others...


function loadXML(loaded) {

if (loaded) {

xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {

image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
location[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
}
firstImage();

} else {

content = "file not loaded!";

}

}

Then you add the getURL so when they click on the image it goes to the link, p is the variable keeping the marker in the array...


picture.onRelease = function {
getURL(p);
}


This is untested, but should give you some help.

crays
12-10-2008, 07:53 AM
Thank you for your reply. I have a picture how i should do it now. But after trying. it always redirect me to a place called website/undefined . My codes is here.

images.xml

<pic>
<image>gallery/haha.jpg</image>
<title>Haha</title>
<description>Haha</description>
<location>gallery/haha.jpg</location>
</pic>


flash code


stop();
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
namai = [];
description = [];
link = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
namai[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
link[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}
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);
name_txt.text = namai[p];
desc_txt.text = description[p];
picture.getURL = link[p];
picture_num();
}
}
}
function prevImage() {
if (p>0) {
p--;
picture._alpha = 0;
picture.loadMovie(image[p],1);
name_txt.text = namai[p];
desc_txt.text = description[p];
picture.getURL = link[p];
picture_num();
}
}
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0],1);
name_txt.text = namai[0];
desc_txt.text = description[0];
picture.getURL = link[0];
picture_num();
}
}




The picture code


on (release) {
getURL(link[p], "_blank");
}

gnomeontherun
12-10-2008, 08:40 AM
Your xml field 'location' should also be named 'link' for consistency, but run traces to figure out if the link is being properly picked up from XML and report back. Put this in the button code as well so when you are testing in Flash it will tell you.


trace(link[p]);

crays
12-11-2008, 10:10 AM
Thanks for all your replies. I've solve the problem. Yet i wonder why i couldn't use

picture.onRelease

but i have to add another movieclip (with alpha = 0) to act as the button.

gnomeontherun
12-11-2008, 12:50 PM
Probably because I had a typo


picture.onRelease = function() {
getURL(p);
}

crays
12-12-2008, 06:29 AM
Oh that's not it, i inserted that () into it. Tho it doesn't work for the onRelease function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum