dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Hyperlink XML Help!?

  1. #1
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315

    Hyperlink XML Help!?

    Experts - I've got some actionscript that I'm working on with much success, however, I'm totally baffeled how to hyperlink portions of the XML generated content.

    Here's my script:

    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;
    		}
    		firstImage();
    	} else {
    		content = "xml not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("images.xml");
    ///////////////////////////////////// end
    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();
    };
    ///////////////////////////////////// end
    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];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		desc_txt.text = description[p];
    		picture_num();
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		desc_txt.text = description[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }
    //end

    XML Values:

    Code:
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
        <pic>
            <image>images/01.jpg</image>
                <caption>TESTING 1,2, 3 - Today's News</caption>
                <url>http://www.cnn.com</url>
        </pic>
    </images>
    Any help would be much appreciated!!

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    add an array to hold the urls,
    use the array[index] along with getURL to open links

    function loadXML(loaded) {
    if (loaded) {
    xmlNode = this.firstChild;
    image = [];
    description = [];
    urls = [];
    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;
    urls[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
    trace(urls[i]);

    }
    firstImage();
    } else {
    content = "xml not loaded!";
    }
    }

  3. #3
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Hmmm - ok. Thanks for the response modified_dog. I've added the arrays, however I don't get where I'm supposed to place the get URL?

    use the array[index] along with getURL to open links

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    as you haven't specified how and where you intend to activate the link
    in your Flash file, I am at a loss as how to give you an answer

  5. #5
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315

    Attachement

    Ok - see the attached portfolio.fla - not sure where to even place the get url... Thanks for your help in advance....
    Attached Files Attached Files

  6. #6
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    OK - maybe to clairfy - as i continue to read forums on this topic. I just need the end of my XML text [Click Here to View] to link to any exernal web address.

    I've tried this with my XML with no sucess:

    <caption>New animated digital signage ad done for Yellow Tail (Australia) TEST3 <a href="http://www.intromotion.com/media">LINK</a></caption>
    Last edited by intromo; 03-21-2008 at 04:43 PM.

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176

    cdata asfunction

    include the link in a cdata section -
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <caption>
    <![CDATA[New animated digital signage ad done for Yellow Tail (Australia) TEST3 <a href='asfunction:openLink,http://www.intromotion.com/media'>LINK</a>]]>
    </caption>
    show the link in an html enabled textfield -
    PHP Code:
    _xml.onLoad = function(){
    testTextField.htmlText this.firstChild.firstChild.nodeValue;
    }; 
    and trigger the link to open in a new window -
    PHP Code:
    function openLink(param){ trace(param);
    getURL(param"_blank");
    }; 

  8. #8
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Ok - may be a stupid question, but where do I place the code? I've tried placing it in the AS, but then the link shows up as the full string?

  9. #9
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    I must be placing these values at the wrong spot... been reading up on this all afternoon with no success. What am I missing?

    Code:
    desc_txt.html = true;
    
    _xml.onLoad = function(){ 
    desc_txt.htmlText = this.firstChild.firstChild.nodeValue; 
    }; 
    
    function openLink(param){ trace(param); 
    getURL(param, "_blank"); 
    }; 
    
    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;
    		}
    		firstImage();
    	} else {
    		content = "xml not loaded!";
    	}
    }
    xmlData = new XML();
    xmlData.ignoreWhite = true;
    xmlData.onLoad = loadXML;
    xmlData.load("images.xml");
    
    
    ///////////////////////////////////// end
    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();
    };
    ///////////////////////////////////// end
    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];
    			picture_num();
    		}
    	}
    }
    function prevImage() {
    	if (p>0) {
    		p--;
    		picture._alpha = 0;
    		picture.loadMovie(image[p], 1);
    		desc_txt.text = description[p];
    		picture_num();
    	}
    }
    function firstImage() {
    	if (loaded == filesize) {
    		picture._alpha = 0;
    		picture.loadMovie(image[0], 1);
    		desc_txt.text = description[0];
    		picture_num();
    	}
    }
    function picture_num() {
    	current_pos = p+1;
    	pos_txt.text = current_pos+" / "+total;
    }
    //end

  10. #10
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    can you zip your xml and a simple file ? ( save as Flash 8 for me )
    post it here and i'll have a look

  11. #11
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    Here you go! - Again thanks for your help!
    Attached Files Attached Files

  12. #12
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    this works here replace your code with this and test -
    PHP Code:
    function loadXML(loaded) {
        if (
    loaded) {
            
    xmlNode this.firstChild;
            
    image = [];
            
    description = [];
            
    total xmlNode.childNodes.length;
            for (
    i=0i<totali++) {
                
    image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                
    description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
            }
            
    firstImage();
        } else {
            
    content "xml not loaded!";
        }
    }

    xmlData = new XML();
    xmlData.ignoreWhite true;
    xmlData.onLoad loadXML;
    xmlData.load("images.xml");

    function 
    openLink(param){ trace(param); 
    getURL(param"_blank"); 
    }; 

    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();
    };

    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.html true;
            
    desc_txt.htmlText description[p];
                
    picture_num();
            }
        }
    }
    function 
    prevImage() {
        if (
    p>0) {
            
    p--;
            
    picture._alpha 0;
            
    picture.loadMovie(image[p], 1);
            
    desc_txt.html true;
            
    desc_txt.htmlText description[p];
            
    picture_num();
        }
    }
    function 
    firstImage() {
        if (
    loaded == filesize) {
            
    picture._alpha 0;
            
    picture.loadMovie(image[0], 1);
            
    desc_txt.html true;
            
    desc_txt.htmlText description[0];
            
    picture_num();
        }
    }
    function 
    picture_num() {
        
    current_pos p+1;
        
    pos_txt.text current_pos+" / "+total;


  13. #13
    I know nothing.
    Join Date
    Feb 2008
    Posts
    315
    OMG! That works like a charm! Thank you so very much! If there's anything you need from me just let me know! Maybe a donation to a fav charity?

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center