twoweektrial Posted June 1, 2010 Share Posted June 1, 2010 I have a slideshow I've been working on for a few hours, and for some reason I can't seem to access global variables Here's the code: // Slideshow processor var images = new Array(); var current = 0; function setup_gallery() { if (window.XMLHttpRequest) { xml=new XMLHttpRequest(); } else { xml=new ActiveXObject("Microsoft.XMLHTTP"); } xml.onreadystatechange=function() { if (xml.readyState==4 && xml.status==200) { images = xml.responseText.split(" "); } } xml.open("GET", "/inc/image_grabber.php", true); xml.send(); $("ss_first").onClick = first(); $("ss_last").onClick = last(); $("ss_next").onClick = next(); $("ss_previous").onClick = previous(); change_image(current); } function change_image(next) { var e = $("picture_frame"); e.href = images[next]; } //The following four functions modify 'current' and then change the image function first() { current = 0; change_image(current); } function last() { current = images.length - 1; change_image(current); } function next() { current++; if(current >= images.length) { current = 0; } change_image(current); } function previous() { current--; if(current <= 0) { current = images.length + 1; } change_image(current); } This is using a php page that returns a string of image names separated by spaces. When I run the code, images[0] is undefined. I may have left out something valuable, but I'm a little frazzled, so thanks in advance for your help. Quote Link to comment Share on other sites More sharing options...
Adam Posted June 2, 2010 Share Posted June 2, 2010 Have you tried to alert the xml.responseText to ensure it's what you're expecting? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.