2 Replies Latest reply on Nov 28, 2008 7:51 AM by c05min.paul

    Variable problem - createEmptyMovieClip dynamic

      Hi, I don't understand what i am writing bad.
      In this code :

      If i replace this.createEmptyMovieClip(name_mc,this.getNextHighestDepth());
      with :this.createEmptyMovieClip( "name_mc" ,this.getNextHighestDepth());
      It works.

      I need 50 square buttons and i need dynamic names, haw i'll writhe the variable code ?

      Thanks for the time,
        • 1. Variable problem - createEmptyMovieClip dynamic
          Ned Murphy Adobe Community Professional & MVP
          name_mc is a string, not the name assigned to a movieclip. So your code is trying to get a string to behave as a movieclip. In this case, dasdasd is the name of the movieclip, so either of the following will work.

          var name_mc = "dasdasd";
          this[name_mc].moveTo(10, 10);
          this[name_mc].lineTo(100, 10);
          this[name_mc].lineTo(100, 100);
          this[name_mc].lineTo(10, 100);
          this[name_mc].lineTo(10, 10);

          var name_mc = "dasdasd";
          dasdasd.moveTo(10, 10);
          dasdasd.lineTo(100, 10);
          dasdasd.lineTo(100, 100);
          dasdasd.lineTo(10, 100);
          dasdasd.lineTo(10, 10);

          In the first version I show, the brackets surrounding the string causes the string to be evaluated as an object (which has the string value of "dasdasd"). The brackets are a very handy tool, especially when you need to loop thru a number of objects or target objects that have names that vary by a digit value... movie1, movie2, etc... -> this["movie"+i]._x in a loop for example.

          Hopefully now you can see why using "name_mc" worked... it was a string assigned as the instance name, not the variable name_mc, and AS2 is forgiving in such matters... AS3 would have stopped you cold because you have two different types being called the same thing.
          • 2. Re: Variable problem - createEmptyMovieClip dynamic
            c05min.paul Level 1
            Thanks for the help ! It is clear for me now.