1 Reply Latest reply on Mar 6, 2007 4:56 PM by tonyhigham

    Create movieClips with a for loop?

    raydowe
      I'm having some trouble, as i'm a noob and still trying to get the hang of object oriented programming.

      I'm trying to create 6 movieClips, numbered thumb01_mc to thumb06_mc, and immediatly load into them images in the folder "media" and named "small01.jpg".

      when i run this code, i get the error message:
      **Error** Scene=Scene 1, layer=actions, frame=59:Line 144: Syntax error.
      var thumb0+i+_mc:MovieClip = this.createEmptyMovieClip("thumb0"+i+,i);

      can anyone tell me what i'm doing wrong?
        • 1. Re: Create movieClips with a for loop?
          tonyhigham Level 1
          There reason you're getting errors is that your concatinating a string when you need to be resolving an object name, and you have an extra + in your MovieClip constructor. However, none of that really matters, because your setup was not quite kosher to begin with. See below for code...

          For reference, you don't need to set up the name for the new mc as a new variable, because you're naming it in the creation method. Also, 'this' will refer to the movieclip with the frame on which you have the code. In the code below, you'll see that I have set up a local reference to the newly created clip, which makes things nice and easy. However, you could also reference it like so:

          this["thumb0"+i].loadMovie(etcetera)

          Once youre more comfortable, check out the MovieClipLoader class instead of loadMovie, since it has nice callbacks to use for preloaders, sizing, and positioning. You obviously have the right idea here, your syntax just wasn't quite right :)