8 Replies Latest reply on Sep 5, 2008 5:21 PM by kglad

    Giving Links To Dynamically Created MC

    system_critical55
      Hi, I've been working on a semi-dynamic portfolio for my personal work. It combines a .swf and an XML file to create a bunch of little boxes, containing thumbnails, images, and links, all dynamically generated. Everything works fine except the link. Here is the ActionScript:


      var boxes = new Array();
      var myXml = new XML();
      boxY = 30;
      myXml.ignoreWhite = true;
      myXml.load("../xml/projects.xml");
      myXml.onLoad = function() {
      for (var i = 0; i<this.firstChild.childNodes[1].childNodes.length; i++) {
      _root.attachMovie('projectBox','box'+i,i,{_y:boxY});
      boxes.push(_root['box'+i]);
      boxY = boxY+45;
      boxes .projectName.text = myXml.firstChild.childNodes[1].childNodes.attributes.pTitle;
      boxes .thumb.loadMovie(myXml.firstChild.childNodes[1].childNodes.attributes.thumb);
      boxes .projectBtn.onRelease = function() {
      getURL(myXML.firstChild.childNodes[1].childNodes
      .attributes.link); // CONSOLE SAYS UNDEFINED
      };
      }
      };

      Here is the XML:


      <?xml version="1.0" encoding="UTF-8"?>

      <projects>

      <websites>
      <project pTitle="Olde Oaks Golf Club" link="#" thumb="../img/oaks.gif" />
      </websites>

      <films>
      <project pTitle="Trans/mission" link=" http://www.westwardmotion.com/projects/films/transmission.html" thumb="../img/transmission.jpg" />
      </films>

      <Writings>
      <project pTitle="Coming Soon" link="#" thumb="../img/placeholder.jpg"/>
      </Writings>

      </projects>

      I think the problem with the getURL() is that the variable i from the for loop changes several times, while the getURL() occurs on with the onClick function. Perhaps at the time of the onClick the variable is undefined. Is there a solution to give these buttons dynamic links? Thanks for helping a noob. It is very much appreciated.