PDA

View Full Version : listBox & XML goto next entry


djungle
04-03-2003, 06:43 PM
Hi,

Is it possible to have a listBox selection pause for, say, 10 seconds and automatically select the next entry?

My Code looks like this.

pics_xml = new XML();
pics_xml.ignoreWhite = true;
pics_xml.onLoad = function(sucess) {
if (sucess) {processList(pics_xml);}
}
// Load up the XML file into Flash
pics_xml.load('pictures.xml');
function processList(List)
{
pictures = new Array();
var children = List.firstChild.childNodes;
for(i = 0; i < children.length; i++)
{
tmp = children[i].childNodes;
tmpObj = new Object();
for(j=0;j<tmp.length;j++)
{
if(tmp[j].nodeName == 'Name') {
lb_myPictures.addItem(tmp[j].firstChild.nodeValue, j);
}
tmpObj[tmp[j].nodeName] = tmp[j].firstChild.nodeValue;
}
pictures.push(tmpObj);
}
lb_myPictures.setChangeHandler("clickHandler");
}//end function processList

function clickHandler()
{
index = lb_myPictures.getSelectedIndex();
trace ("Show " + pictures[index].Name + " Picture");

loadMovie(pictures[index].picLink,_root.myPics);
}

Thanks
Django

freddycodes
04-03-2003, 07:22 PM
I couldn't test it, for obvious reasons(no xml, no jpgs, no fla) but this should work using setInterval


curIdx = 0;
function incrementIdx()
{
lb_myPictures.setSelectedIndex(curIdx);
curIdx++;
if(curIdx > lb_myPictures.getLength()) {
curIdx = 0;
}
clickHandler();
}
myInterval = setInterval(incrementIdx, 10000);
function clickHandler()
{
index = lb_myPictures.getSelectedIndex();
curIdx = index;
trace ("Show " + pictures[index].Name + " Picture");

loadMovie(pictures[index].picLink,_root.myPics);
}

djungle
04-03-2003, 07:40 PM
Thanks freddy,

Close but for some reason it shows the same picture(ie. doesn't go to the next one in the list).

I'm starting to understant this actionscript stuff:) but I'm still a little shakey, can't tell where the code is wrong...

freddycodes
04-03-2003, 07:47 PM
I think its because of this line.


curIdx = index;


Which was supposed to deal with someone actually clicking the listbox. But instead it resets the curIdx back to 0 each time.
Try this instead


curIdx = 0;
function incrementIdx()
{
lb_myPictures.setSelectedIndex(curIdx);
trace ("Show " + pictures[curIdx].Name + " Picture");
loadMovie(pictures[curIdx].picLink,_root.myPics);
curIdx++;
if(curIdx > lb_myPictures.getLength()) {
curIdx = 0;
}
}
myInterval = setInterval(incrementIdx, 10000);
function clickHandler()
{
index = lb_myPictures.getSelectedIndex();
clearInterval(myInterval);
trace ("Show " + pictures[index].Name + " Picture");
loadMovie(pictures[index].picLink,_root.myPics);
curIdx = index;
myInterval = setInterval(incrementIdx, 10000);
}

djungle
04-03-2003, 08:13 PM
Thanks Alot Freddy:cool: you da man!