3 Replies Latest reply on Sep 13, 2006 4:33 PM by Rothrock

    assign a fixed variable to a range of  new created mc's


      i have another issue. when creating a number of movies (i=1,2,3, ...) wich have to act like a button, i put a code on the new created movieclip like this one included.

      the problem is that each button_mc must memorize his ID, in fact "i" (the first one has ID=1; the second ID=2; ...), but at the end of the while-action, all button remember the last "i"-value...

      Does someone know a solution for this problem?

        • 1. Re: assign a fixed variable to a range of  new created mc's
          Rothrock Level 5
          First something that doesn't answer your question and something that does. Here is a little trick. The createEmptyMovieClip method returns a reference to the newly create clip so your code could be written:

          var curClip=this.createEmptyMovieClip("mc_back"+j);
          //and so on…

          But now I see two problems. First the one you have mentioned. As you are noticing, that you are putting "j" inside the onRelease handler. But that is a reference to "j" not the actual value of it. So when the onRelease handler is called later, its value is the last value because it is the current value of "j." So basically you need to do what you have suggested (see you knew the answer and didn't even know it!) in your post. You need each clip to have its own ID. So you could put this kind of code right after you create the empty movie clip.


          And then in the onRelease handler:


          But this goes to the other problem which I think you will run into. When you load external resources into a clip the clip is "reset" to its default status once the contents are loaded in. So both the myID property and the onRelease handler will be erased when the button.jpg art is loaded into mc_back+j clip.

          You might not have experienced this yet because you are in the testing environment or testing from your local machine, but if you will be trying this over the web you will eventually run into this problem.

          So here is what I might suggest. Create your mc_back+j movieclips.
          Assign the myID and onRelease to the mc_back+j clip.
          Inside each of the mc_backs create a clip called "art" or some such.
          Load the external jpg into the art clip.

          • 2. Re: assign a fixed variable to a range of  new created mc's
            bibberlam Level 1
            this is a great answer! it works fine.

            i didn't have the problem you noticed with settings wich would be reset to default when loading the jpg, because I did not use the jpg (just by example). instead of this, I use a movieclip filler wich give something to click on...


            thanks, it was really helpful
            • 3. Re: assign a fixed variable to a range of  new created mc's
              Rothrock Level 5
              Great, don't forget my trick. If _root["mc_back"+r+j] was created using createEmptyMovieClip() you could use the returned reference to "tidy" up the drawing code. Just me, but I've always found curClip is much easier to type correctly than _root["mc_back"+r+j] is! :)