;

PDA

Click to See Complete Forum and Search --> : Action Script Button Function Help


walkerau
01-04-2008, 09:11 PM
I'm having problems with the following script I'm using for an XML photo gallery.

for (i=0; i<49; i++) {
if (category[i] == "online") {
if (b<50) {
thumbbutton = this["a"+(b+1)];
thumbbutton.loadMovie(thumb[i], 1);
button = this["bt"+(i+1)];
button.onRollOver = function() {
company_txt.text = company[i];
description_txt.text = description[i];
url_txt.text = url[i];

};
}
b++;
}
}

The "i" variable works fine until it gets to the button.onRollOver function. I did a trace and "i" is always 49. It should never be 49 because the For loop should break at 49. Any suggestions as to why this is happening? I did a trace before the function, and I got 3 and 5 - there is the "online" tag at this position in the XML. Thanks!

a_modified_dog
01-05-2008, 07:10 AM
add events outside of the for(loop)
loops only update on the last iteration (hence all are 49)

for (var i=0; i<49; i++) {
if (category[i] == "online") {
if (b<50) {
thumbbutton = this["a"+(b+1)];
thumbbutton.loadMovie(thumb[i], 1);
button = this["bt"+(i+1)];
addEvents(button, i);
}
b++;
}
}

function addEvents(btn,id){
btn.onRollOver = function() {
company_txt.text = company[id];
description_txt.text = description[id];
url_txt.text = url[id];
};
};hth :)