3 Replies Latest reply on Aug 31, 2006 12:19 PM by tony_b_48

    Dynamic Movie Clip Instance Names

    tony_b_48
      Hello,
      I must load photos from a database at runtime. I thought to create empty movie clips then load them with the photos. I create the empty movie clips in a loop with:
      this.createEmptyMovieClip("plane_index_photo_" +i +"_mc", this.getNextHighestDepth());
      In the debugger, it looks like they are all there.
      Later, I try to populate them in another loop with:
      bob = ("plane_index_photo_" + i + "_mc");
      bob.loadMovie(" http://www.tonybarre.com/directory/images/" + z);
      Where z is early calculated as the image name.
      This doesn't seem to work.
      For debugging, I bypassed the loop and substituted:
      plane_index_photo_1_mc.loadMovie(" http://www.tonybarre.com/directory/images/" + z);
      This worked fine, reassuring me that the database works fine and the problem is probably with my syntax. Can you help?

      Thanks
      Tony
        • 1. Re: Dynamic Movie Clip Instance Names
          Level 7

          "tony_b_48" <webforumsuser@macromedia.com> wrote in message
          news:ecla7l$f0s$1@forums.macromedia.com...
          > Hello,
          > I must load photos from a database at runtime. I thought to create empty
          > movie clips then load them with the photos. I create the empty movie
          > clips in
          > a loop with:
          > this.createEmptyMovieClip("plane_index_photo_" +i +"_mc",
          > this.getNextHighestDepth());

          This looks okay. For the most part I like to use i as the depth to load the
          movie into rather that getNextHighestDepth().

          > In the debugger, it looks like they are all there.
          > Later, I try to populate them in another loop with:
          > bob = ("plane_index_photo_" + i + "_mc");
          > bob.loadMovie(" http://www.tonybarre.com/directory/images/" + z);
          > Where z is early calculated as the image name.
          > This doesn't seem to work.
          > For debugging, I bypassed the loop and substituted:

          You cant reference a MovieClip like this.

          try:
          this["plane_index_photo_"+i+"_mc"].loadMovie(.....);

          Or, as I do, you can create an Array to start, add the instances to the
          Array and access them that way. For example.

          var myArray:Array;

          run for loop with i {
          var photoMC = this.createEmptyMovieClip("plane_index_photo_"+i+"_mc",
          i);
          myArray.push(photoMC);
          }

          run for loop with i less than myArray.length

          for (var i:Number = 0; i < myArray.length; i++) {
          myArray .loadMovie(.....);
          }






          > plane_index_photo_1_mc.loadMovie(" http://www.tonybarre.com/directory/images/"
          > +
          > z);
          > This worked fine, reassuring me that the database works fine and the
          > problem
          > is probably with my syntax. Can you help?
          >
          > Thanks
          > Tony
          >


          • 2. Re: Dynamic Movie Clip Instance Names
            tony_b_48 Level 1
            Hello,
            Thank you very much for the quick response. The second loop still seems to fail.
            As you suggested, I replaced the first loop with the following:
            var maxSize:Number = 50;
            var indexPhotoArray:Array;
            for (var i:Number = 0; i<maxSize; i++) {
            var photoMC = this.createEmptyMovieClip("plane_index_photo_"+i+"_mc", i);
            indexPhotoArray.push(photoMC);
            When I look in the debugger, all 50 empty movie clips show up fine.
            Based on your suggestion, the second loop goes:
            _root.business_mc.business_ds.first();
            for (var i:Number = 0; i < indexPhotoArray.length; i++) {
            var z:String =_root.business_mc.business_ds.currentItem.Picture;
            indexPhotoArray.loadMovie(" http://www.tonybarre.com/directory/images/" + z);
            _root.business_mc.business_ds.next();
            }
            As before, if I replace this loop with:
            _root.business_mc.business_ds.first();
            var z:String =_root.business_mc.business_ds.currentItem.Picture;
            plane_index_photo_1_mc.loadMovie(" http://www.tonybarre.com/directory/images/" + z);
            I get the one photo. But, of course, I need the whole array.
            Did I misunderstand your recommendation?
            Thanks
            Tony
            • 3. Re: Dynamic Movie Clip Instance Names
              tony_b_48 Level 1
              I have solved this problem (although I am sure I will be back with others). I am new to this forum -- is there a way I am supposed to mark this thread "closed" or "resolved". Thanks for the help.