5 Replies Latest reply on Jan 15, 2007 7:45 AM by kglad

    duplicateMovieClip() issue with XML

    w33zel
      The problem I'm having in the code below, is that only the last iteration of the loop is being displayed on the page. The trace commands output everything as though the movie clips have been made, but they don't show up when I test the movie. Please help:

      function loadlinks() {
      array = XMLarray[0][2];
      index = 0;
      for (var i in array) {
      if (array ["tag"] == "link") {
      linksrc = XMLarray[0][2]
      ["src"];
      linktitle = XMLarray[0][2] ["title"];
      trace("linktitle="+linktitle);
      mylink = imgpath+linksrc;
      trace("mylink="+mylink);
      //duplicateMovieClip(mainlinksmc.linkmc, newname="linkmc"+index, this.getNextHighestDepth());
      var myLinkMc:MovieClip = mainlinksmc.linkmc.duplicateMovieClip("linkmc"+index, this.getNextHighestDepth());
      trace(myLinkMc);
      myLinkMc.linktext.htmlText=linktitle;
      myLinkMc.mylink=mylink;
      myLinkMc._y=(index+1)*20;
      myLinkMc._x=0;
      myLinkMc.onRelease = changeLink;
      var myLinkMc = null;
      index++;
      }
      }
      }
        • 1. Re: duplicateMovieClip() issue with XML
          kglad Adobe Community Professional & MVP
          first, use the attach code option to display actionscript in this forum. otherwise, your code looks like your message above and that's difficult to interpret.

          second, if myLinkMc needs to retrieve the value of index when it was created, then you'll need to store that value so myLinkMc can retrieve it. the following would be a typical way to do this:

          • 2. Re: duplicateMovieClip() issue with XML
            w33zel Level 1
            myLinkMc doesn't really care about the index variable. That's just being used to name it and set its depth. I just don't understand why this loop goes through everything, and then only really outputs the last duplicated clip.
            • 3. duplicateMovieClip() issue with XML
              mxc Level 1
              I cant really see everything from your code but....
              You need to create a new object and function for each clip otherwise only the last one will be created. I pasted an example below. Sorry I cant comment more right now. Hope you see what I mean.

              function loadlinks() {
              array = XMLarray[0][2];
              index = 0;
              for (var i in array) {
              if (array["tag"] == "link") {
              linksrc = XMLarray[0][2]["src"];
              linktitle = XMLarray[0][2]["title"];
              trace("linktitle="+linktitle);
              mylink = imgpath+linksrc;
              trace("mylink="+mylink);
              //duplicateMovieClip(mainlinksmc.linkmc, newname="linkmc"+index, this.getNextHighestDepth());
              var myLinkMc:MovieClip = mainlinksmc.linkmc.duplicateMovieClip("linkmc"+index, this.getNextHighestDepth());

              this["linkmc"+index].linktext.htmlText=linktitle;
              this["linkmc"+index].mylink=mylink;
              this["linkmc"+index]._y=(index+1)*20;
              this["linkmc"+index]._x=0;
              this["linkmc"+index].onRelease = changeLink;
              var myLinkMc = null;
              index++;
              }
              }
              }
              • 4. Re: duplicateMovieClip() issue with XML
                w33zel Level 1
                It looks like all you changed was instead of "myLinkMc..." it is "this["linkmc"+index]..."

                Let me attach the code so that it's easier to read...
                • 5. Re: duplicateMovieClip() issue with XML
                  kglad Adobe Community Professional & MVP
                  1. trace(this.getNextHighestDepth()) to make sure you have no component issues.

                  2. trace(myLinkMc._y) to make sure your movieclips aren't hiding each other.

                  3. how do you know it's the last iteration being displayed?