I have set up a number of loader objects and set up locations of the images I
want to load and link urls I want assigned to each image using loops like this:
for (var j = 1; j<url_XML.firstChild.childNodes.length/2+1; j++) {
images[j]=this.createClassObject(mx.controls.Loader, "myLoader"+j, j);
images[j].scaleContent = false;
}
for (var i=0; i<url_XML.firstChild.childNodes.length; i++) {
if (i < url_XML.firstChild.childNodes.length/2) {
urls[i] = url_XML.firstChild.childNodes[i].childNodes;
}
else {
links[i-(url_XML.firstChild.childNodes.length/2)] =
url_XML.firstChild.childNodes[i].childNodes;
}
}
This worked great, and then I used a loop to assign each image to the page
like this:
for (var i=0; i<urls.length; i++) {
images[i+1].contentPath = urls[i];
images[i+1]._x = i*320;
images[i+1]._y = 0;
}
This also worked great, but when I used the following loop to set up a link
url for each image, the link does not work:
for (k=0; k<links.length; k++) {
images[k+1].onRelease = function() {
getUrl(links[k]);}
}
}
When I just used this it worked fine for the one function:
var k = 0;
images[k+1].onRelease = function() {
getUrl(links[k]);}
But I can not get the loop to work so I actually create all functions. Any
ideas what I'm doing wrong and what I can do to make it work? Thanks for any
help!
Bob
kglad - 31 Jul 2008 23:12 GMT
use the attach code option to display code in this forum.
and when images[k+1] is released, it doesn't know it has any relationship to
the value that k has when your onRelease is defined. assign a property of
images[k+1] to store the value of k and use that property in you onRelease
handler.