1 Reply Latest reply on Oct 27, 2010 9:52 AM by kglad

    How to code this?

    Ron Colmen Level 2

      I've got 10 font types embedded and 10 buttons to select a font. I'm a bit lost here, how to code all the 10 buttons to apply the relevant font type when each button is clicked.

       

      var dyofnt_fmt:TextFormat = new TextFormat();

      var theFont:Array = [font1,font2,font3,...];

      var theButton:Array = [button1,button2,button3,button4,.....];

       

      for(k=1; k<9; k++){

           for(i=0; i<theFont.length; i++){

      this["button"+k].onRelease = function() {

                dyofnt_fmt.font = this["theFont"+k][i];

                this["theFont"+k][i].setTextFormat(dyofnt_fmt);

                this["theFont"+k][i].embedFonts = true;

      };

      this["theFont"+k][i].setNewTextFormat(dfont_fmt);

           }

      }

        • 1. Re: How to code this?
          kglad Adobe Community Professional & MVP

          use:

           

          if those are movieclip buttons and theFont contains linkage ids of fonts, you can use:


          var dyofnt_fmt:TextFormat = new TextFormat();

          var theFont:Array = [font1,font2,font3,...];

          var theButton:Array = [button1,button2,button3,button4,.....];

           

           

          for(k=1; k<9; k++){

               for(i=0; i<theFont.length; i++){

          theButton[k].kvar=k;  // if not a movieclip, you'll need to use the _name property of your buttons

          theButton[k].onRelease = function() {

                    dyofnt_fmt.font = theFont[this.kvar];

                 yourTextField.setTextFormat(dyofnt_fmt);

          yourTextField.setNewTextFormat(dyofnt_fmt);

           

           

          };

               }

          }