Jump to content

Undefined global variable issue


twoweektrial

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.