Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Loading different link to a getURL

    Hi, i'm using a XML and flash photogallery as in this tutorial http://www.kirupa.com/developer/mx20...togallery9.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.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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)
    Code:
    <?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...

    Code:
    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...

    Code:
    picture.onRelease = function {
        getURL(p);
    }
    This is untested, but should give you some help.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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
    Code:
        <pic>
            <image>gallery/haha.jpg</image>
            <title>Haha</title>
    	<description>Haha</description>
    		<location>gallery/haha.jpg</location>
        </pic>
    flash code
    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
    Code:
    on (release) {
    	getURL(link[p], "_blank");
    }

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    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.

    Code:
    trace(link[p]);
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Probably because I had a typo

    Code:
    picture.onRelease = function() {
        getURL(p);
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Oh that's not it, i inserted that () into it. Tho it doesn't work for the onRelease function.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •