-
(CS3 AS2) Ignoring or replacing empty nodes
Hi guys,
I've got an XML driven gallery with a text field for an image caption.
All is well, but, not all the images have captions and so at the moment I'm getting "undefined"
I have faced this problem before when pulling data from an rss feed and adding to a string but this time there's no string...
Below is the AS which has been adapted from a kirupa tut (i think) and I've attempted to add the solution which I used with the rss feed issue but it doesn't quite seem to work..
Any help would be great!
Cheers
Code:
//IMAGES
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
caption = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
}
caption[i] == undefined ? caption[i] = "--" : null;
}
preloadImages(0);
} else {
content = "file not loaded!";
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://www.domain.com.au/scripts/productImages.php");
-
FK'n_dog
PHP Code:
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
caption[i] == undefined ? caption[i] = "--" : null; // moved to be within the loop
}
-
Thank modified_dog for you quick response!
I had already tried including the lione as part of the loop but unfortuantely it didn't work..
I've included the full iamge script incase you can see why it's failing...
Thanks again for your help..
PHP Code:
//IMAGES-------------------------------------------------------------------
function loadXML(loaded) { if (loaded) { xmlNode = this.firstChild; image = []; caption = []; total = xmlNode.childNodes.length; for (i=0; i<total; i++) { image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue; caption[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue; caption[i] == undefined ? caption[i] = "--" : null;
} preloadImages(0);
} else { content = "file not loaded!"; } } xmlData = new XML(); xmlData.ignoreWhite = true; xmlData.onLoad = loadXML; xmlData.load("http://www.domain.com.au/scripts/productImages.php"); //----------------------------------------------------------------------------------- listen = new Object(); listen.onKeyDown = function() { if (Key.getCode() == Key.LEFT) { prevImage(); } else if (Key.getCode() == Key.RIGHT) { nextImage(); } }; Key.addListener(listen); prevBt.onRelease = function() { prevImage(); }; nextBt.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 += 5; } } }; function nextImage() { if (p<(total-1)) { p++; //next._visible = true; if (loaded == filesize) { picture._alpha = 0; picture.loadMovie(image[p],1); captions.text = caption[p]; picture_num(); } } } function prevImage() { if (p>0) { p--; //prev._visible = true; picture._alpha = 0; picture.loadMovie(image[p],1); captions.text = caption[p]; picture_num(); } }
function firstImage() { if (loaded == filesize) { picture._alpha = 0; picture.loadMovie(image[0],1); captions.text = caption[0]; picture_num(); prev._visible = false; } } function picture_num() { current_pos = p+1; pos_txt.text = current_pos+" / "+total; if (current_pos == 1) { prev._visible = false; } if (current_pos>1) { prev._visible = true; } if (current_pos == total) { next._visible = false; } if (current_pos<total) { next._visible = true; } }
var count:Number = 0; this.createEmptyMovieClip("container",this.getNextHighestDepth()); container._alpha = 0;
function preloadImages(count) { image_mcl.loadClip(image[count],"container"); }
image_mcl = new MovieClipLoader(); loadlistener = new Object(); image_mcl.addListener(loadlistener);
loadlistener.onLoadInit = function(target_mc) { loadText.text = "loading image "+count+" of "+total+""; count++; if (count<total) { preloadImages(count); } else { loadText.text = ""; container.removeMovieClip(); firstImage(); } };
-
FK'n_dog
xmlData.load("http://www.domain.com.au/scripts/productImages.php");
please supply the correct url to the php file (or post your xml file) so i can test
-
H modified_dog,
I'm really sorry but I was testing the wrong category (there's about 15)
But the good news is that it work a treat!
Thanks heaps for the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|