Help! XML undefined nodes in dynamic text field

I’m a nooby to actionscript. I’ve modified the xml photo gallery from the tutorial on this site to include a thumbnail scroller, the previous and next buttons to loop around, and added links to the images so that a pdf will pop up if the image is clicked for the images that have pdfs with the help of this forum.

I’m trying to incorporate a dynamic text box that says “Click on image below to view PDF” only for the images that have a pdf to click on and not for those that don’t have a pdf linked. Therefore I’ve set up XML nodes that say “Click on image below to view PDF” and others that are empty or “undefined” for the ones that don’t have a pdf linked.

Right now it’s almost there. The key lines in the code below I think:

        linkdes_txt.text._visible=false;
            } else {
            linkdes_txt.text._visible=true;
            linkdes_txt.text = linkdes[p];
            }

linkdes_txt is the instance name of the dynamic text field. linkdes[p] refers to the xml node. The here’s the code below. I’ve also attached a zipped file of the .fla file.

XML Code:


<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway1.jpg</image>
        <caption>Poster/Brochure: Poster Side</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway1.jpg</thumbnail>
        <link>http://www.kristinemorical.com/design/print/unitedway/UnitedWayPosterBroc26x26.pdf</link>
        <linkdes></linkdes>
    </pic>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway2.jpg</image>
        <caption>Poster/Brochure: Brochure Side</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway2.jpg</thumbnail>
        <link>http://www.kristinemorical.com/design/print/unitedway/UnitedWayPosterBroc26x26.pdf</link>
        <linkdes>Click on image below to view PDF</linkdes>
    </pic>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway3.jpg</image>
        <caption>Large Envelopes</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway3.jpg</thumbnail>
        <link></link>
        <linkdes></linkdes>
    </pic>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway4.jpg</image>
        <caption>#10 Envelopes</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway4.jpg</thumbnail>
        <link></link>
        <linkdes></linkdes>
    </pic>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway5.jpg</image>
        <caption>Website Concept</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway5.jpg</thumbnail>
        <link></link>
        <linkdes></linkdes>
    </pic>
    <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway6.jpg</image>
        <caption>Website Graphics</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway6.jpg</thumbnail>
        <link></link>
        <linkdes></linkdes>
    </pic>
     <pic>
        <image>http://www.kristinemorical.com/design/print/unitedway/unitedway7.jpg</image>
        <caption>Website Graphics</caption>
        <thumbnail>http://www.kristinemorical.com/design/print/unitedway/thumbs/unitedway7.jpg</thumbnail>
        <link></link>
        <linkdes></linkdes>
    </pic>
</images>

Actionscript Code:


function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        image = [];
        description = [];
        link = [];        
        linkdes = [];        
        thumbnails = [];
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
            description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
            thumbnails* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
            link* = xmlNode.childNodes*.childNodes[3].firstChild.nodeValue;
            linkdes* = xmlNode.childNodes*.childNodes[4].firstChild.nodeValue;
            thumbnails_fn(i);

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

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://www.kristinemorical.com/photo_galleries/photogallery_mxfolder/testgallery2_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;
        }
    }

picture.onRelease = function() {
if(link[p]!=null){
         getURL(link[p], "_blank");
}
     };
};

function nextImage() {
    if (p<(total-1)) {
        p++;
        if (loaded == filesize) {
            picture._alpha = 0;
            picture.loadMovie(image[p], 1);
            desc_txt.text = description[p];
            if (linkdes[p] == undefined) {
            linkdes_txt.text._visible=false;
                } else {
                linkdes_txt.text._visible=true;
                linkdes_txt.text = linkdes[p];
                }
            picture_num();
        }
    } else{
        p = 0;
        if (loaded == filesize) {
            picture._alpha = 0;
            picture.loadMovie(image[p], 1);
            desc_txt.text = description[p];
            //linkdes_txt.text = linkdes[p];//
            if (linkdes[p] == undefined) {
            linkdes_txt.text._visible=false;
                } else {
                linkdes_txt.text._visible=true;
                linkdes_txt.text = linkdes[p];
                }
            picture_num();
        }
    }
}

function prevImage() {
    if (p>0) {
        p--;
        picture._alpha = 0;
        picture.loadMovie(image[p], 1);
        title_txt.text = heading[p];
        desc_txt.text = description[p];
        /*linkdes_txt.text = linkdes[p];*/
        if (linkdes[p] == undefined) {
        linkdes_txt.text._visible=false;
            } else {
            linkdes_txt.text._visible=true;
            linkdes_txt.text = linkdes[p];
            }
        picture_num();
    } else if (p==0) {
        p=(total-1);
        if (loaded == filesize) {
            picture._alpha = 0;
            picture.loadMovie(image[p],1);
            title_txt.text = heading[p];
            desc_txt.text = description[p];
            /*linkdes_txt.text = linkdes[p];*/
            if (linkdes[p] == undefined) {
            linkdes_txt.text._visible=false;
                } else {
                linkdes_txt.text._visible=true;
                linkdes_txt.text = linkdes[p];
                }
            picture_num();
        }
    }
}
function firstImage() {
    if (loaded == filesize) {
        picture._alpha = 0;
        picture.loadMovie(image[0], 1);
        desc_txt.text = description[0];
        
        if (linkdes[p] == undefined) {
            linkdes_txt.text._visible=false;
            } else {
                linkdes_txt.text._visible=true;
                linkdes_txt.text = linkdes[p];
                }

        
        picture_num();
    }
}
function picture_num() {
    current_pos = p+1;
    pos_txt.text = current_pos+" / "+total;
}
function thumbNailScroller() {
    // thumbnail code! 
    this.createEmptyMovieClip("tscroller", 1000);
    scroll_speed = 10;
    tscroller.onEnterFrame = function() {
        if ((_root._ymouse>=thumbnail_mc._y) && (_root._ymouse<=thumbnail_mc._y+thumbnail_mc._height)) {
            if ((_root._xmouse>=(hit_right._x-40)) && (thumbnail_mc.hitTest(hit_right))) {
                thumbnail_mc._x -= scroll_speed;
            } else if ((_root._xmouse<=(hit_left._x+40)) && (thumbnail_mc.hitTest(hit_left))) {
                thumbnail_mc._x += scroll_speed;
            }
        } else {
            delete tscroller.onEnterFrame;
        }
    };
}
function thumbnails_fn(k) {
    thumbnail_mc.createEmptyMovieClip("t"+k, thumbnail_mc.getNextHighestDepth());
    tlistener = new Object();
    tlistener.onLoadInit = function(target_mc) {
        target_mc._x = hit_left._x+(target_mc._width+10)*k;
        target_mc.pictureValue = k;
        target_mc.onRelease = function() {
            p = this.pictureValue-1;
            nextImage();
        };
        target_mc.onRollOver = function() {
            this._alpha = 50;
            thumbNailScroller();
        };
        target_mc.onRollOut = function() {
            this._alpha = 100;
        };
    };
    image_mcl = new MovieClipLoader();
    image_mcl.addListener(tlistener);
    image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);
}

Any help would be greatly appreciated.

Thanks,
Kristine :slight_smile: