1 Reply Latest reply on Jul 31, 2008 3:12 PM by kglad

    onRelease function

    BobMelnyk Level 1
      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 = url_XML.firstChild.childNodes.childNodes;
      else {
      links[i-(url_XML.firstChild.childNodes.length/2)] = url_XML.firstChild.childNodes .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
      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() {

      When I just used this it worked fine for the one function:
      var k = 0;
      images[k+1].onRelease = function() {

      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!


      I have since figured this out. This is what I used, and it works fine:

      for (var i=0; i<links.length; i++) {
      images[i+1].iVar = i;
      images[i+1].onRelease = function() {

        • 1. Re: onRelease function
          kglad Adobe Community Professional & MVP
          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.