9 Replies Latest reply on Aug 7, 2006 6:31 PM by kglad

    Variable Movie Clip Name

    Metzen2K
      Hi,

      How can I make a dynamically created movie clip name variable?

      var font_mc:MovieClip = this.createEmptyMovieClip("font", 1);
      font_mc.loadMovie("fonts/myFont.swf");

      I'd like to be able to specify dynamically create "font_mc", like:

      var "font" + i + "_mc":MovieClip = this.createEmptyMovieClip("font", 1);
      "font" + i + "_mc".loadMovie("fonts/myFont.swf");

      Thanks,
      Brian
        • 1. Re: Variable Movie Clip Name
          kglad Adobe Community Professional & MVP
          try:

          • 2. Re: Variable Movie Clip Name
            Metzen2K Level 1
            Thanks, but that didn't work.

            Below is the code that works, but isn't variable and duplicatable. The font_mc is the part I need to duplicate, the "font" declared in createEmptyMovieClip() isn't used.

            Basically I'm loading an external .swf with an embedded font, and need to create the new text field ON THAT movie clip in order for the externally embedded font to work.

            Thanks,
            Brian

            • 3. Re: Variable Movie Clip Name
              kglad Adobe Community Professional & MVP
              the code i gave would work if used correctly. show how you used that code.
              • 4. Re: Variable Movie Clip Name
                Metzen2K Level 1
                Hi,

                Thanks for the help. I still can't get it to work.

                Here is the code that works:

                var font_mc:MovieClip = this.createEmptyMovieClip("font", 1);
                font_mc.loadMovie("fonts/myFont.swf");

                myButton.onRelease = function() {
                font_mc.createTextField("txt", 1, 0, 0, 150, 20);
                var txt_mc:TextField = font_mc.txt;
                txt_mc.embedFonts = true;
                txt_mc.text = "testing";

                var my_fmt:TextFormat = new TextFormat();
                my_fmt.font = "myFont";
                txt_mc.setTextFormat(my_fmt);
                }

                Here is the code that doesn't work:

                var mc:MovieClip = this.createEmptyMovieClip("font"+i+"_mc", 1);
                this["font" + i + "_mc"].loadMovie("fonts/myFont.swf");

                myButton.onRelease = function() {
                this["font" + i + "_mc"].createTextField("txt", 1, 0, 0, 150, 20);
                var txt_mc:TextField = font_mc.txt;
                txt_mc.embedFonts = true;
                txt_mc.text = "testing";

                var my_fmt:TextFormat = new TextFormat();
                my_fmt.font = "myFont";
                txt_mc.setTextFormat(my_fmt);
                }

                myFont.swf is just an empty .swf with a font embedded, named myFont.

                Thanks,
                Brian
                • 5. Re: Variable Movie Clip Name
                  kglad Adobe Community Professional & MVP
                  "this" on your timeline refers to your timeline. inside your myButton.onRelease handler it refers to myButton.

                  try:

                  • 6. Re: Variable Movie Clip Name
                    Metzen2K Level 1
                    Thanks, but that still doesn't work.

                    I'm new to Flash, but I still think it's because in the code that works it's the font_me in "var font_mc:MovieClip" that is referred to later on, no the "font" in createEmptyMovieClip.

                    But when I try to make that a dynamic variable name, it fails with the error "Identifier Expected":

                    var this["font" + i + "_mc"]:MovieClip = this.createEmptyMovieClip("whatever", 1);
                    this["font" + i + "_mc"].loadMovie("fonts/myFont.swf");

                    Thanks,
                    Brian
                    • 7. Re: Variable Movie Clip Name
                      Metzen2K Level 1
                      OK, it works now. I found another reference to "font_mc" that I hadn't changed to use the dynamic variable reference.

                      Thanks for the help!

                      Brian
                      • 8. Re: Variable Movie Clip Name
                        Metzen2K Level 1
                        OK, it works now. I found another reference to "font_mc" that I hadn't changed to use the dynamic variable reference.

                        Thanks for the help!

                        Brian
                        • 9. Re: Variable Movie Clip Name
                          kglad Adobe Community Professional & MVP
                          you're welcome.