3 Replies Latest reply on May 8, 2007 4:30 AM by cubed-percy

    Stepping through an array

    cubed-percy
      Hi,

      I have an xml file arranged like this:
      <images>
      <pic>
      <image> http://localhost/flashplaceholder1.jpg</image>
      <caption> http://localhost/flashplaceholder1.jpg</caption>
      </pic>
      <pic>
      <image> http://localhost/flashplaceholder2.jpg</image>
      <caption> http://localhost/flashplaceholder2.jpg</caption>
      </pic>
      </images>

      The XML file holds eight images in total. the actionscript loads the xml, navigates to 'image' and 'caption' node values and stores them into two arrays.

      The actionscript then displays each image one after the other in a movieclip that fills the whole stage area. What I want to do is assign the link contained in 'caption' to the relavant image displayed in the movie clip.

      I have done this:


      for (i=0; i<total; i++) {

      image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
      description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
      var nextURL = description ;
      clickable.onRelease = function() {
      getURL("" + nextURL, "_blank");
      trace(nextURL);
      }
      }


      The problem I have is that 'nextURL' in the onRelease function only assigns the last link every time to the movieclip. Is there a way to get each array value to be an active link every time the image displays.

        • 1. Stepping through an array
          shikozel
          you can assign the url property to each button like that:

          image = xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
          description = xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
          var nextURL = description;

          clickable.nextURL=nextURL

          clickable.onRelease = function() {
          getURL("" + this.nextURL, "_blank");
          trace(this.nextURL);
          }
          }
          • 2. Re: Stepping through an array
            cubed-percy Level 1
            Hiya,

            Thanks for your help shikozel! I am still having probrlms with this. I incorrectly wrote the code out in my example. It should have been this:

            I have tried your example but only the last image in the array is displayed regardless of what image I click on.
            • 3. Re: Stepping through an array
              cubed-percy Level 1
              I think I know what the problem is. The loop is going round and assigns each node value to the variable nextURL, but overwrites each one as it does, so nextURL is always equal to the last URL path. Does anyone know of a way to assign each URL path to it's sibling image for the duration it is on screen?