4 Replies Latest reply on Aug 2, 2007 3:25 PM by script

    embed fonts (html = true)  ->createTextField

    chrisatflash Level 1
      Hello, when i am creating a text field like this code below the bold and italic style does not work.
      I know before i post a similar problem. But this was with a textfield placed on the stage.
      You had to place a dummy text in it and make one letter bold and one letter italic to make it work.

      But i don't know how to do this using the createTextField method.

      Does anyoneknow how ? Or is this a bug in Flash?

      var my_fmt:TextFormat = new TextFormat();
      my_fmt.font = "csverdana";
      my_fmt.size = 16;
      my_fmt.align = "left";

      createTextField("veldje_txt",99, 50, 50, 450, 300);

      veldje_txt.border = false;
      veldje_txt.wordWrap = true;
      veldje_txt.multiline = true;
      veldje_txt.embedFonts = true; // turn this of and on to see the difference..
      veldje_txt.selectable = false;
      veldje_txt.antiAliasType = "advanced";
      veldje_txt.thickness = 100;
      veldje_txt.sharpness = 10;
      veldje_txt.setNewTextFormat(my_fmt);
      veldje_txt.styleSheet = astyles;
      veldje_txt.html = true;
      veldje_txt.selectable = true;
      veldje_txt.type = "dynamic";
      veldje_txt.htmlText = "<b>This should be boldt</b><i> and this should be italic</i>";


        • 1. Re: embed fonts (html = true)  -&gt;createTextField
          kglad Adobe Community Professional & MVP
          embed all the fonts you need in your library, give them distinct linkage ids, create a textformat object for each font and assign the font property to your textformat objects to establish the correspondence between your textformat objects and your fonts. finally use setTextFormat() to assign the desired format to your textfield's htmlText property.

          or use css with your embedded fonts with distinct linkage ids.
          • 2. Re: embed fonts (html = true)  -&gt;createTextField
            chrisatflash Level 1
            Okay, i think i got it.. it works, but it sure takes a lot of work..

            Is this now the correct way to do it?

            var my_fmt:TextFormat = new TextFormat();
            my_fmt.font = "csverdana";
            my_fmt.size = 16;
            my_fmt.align = "left";

            veldje_txt.border = false;
            veldje_txt.wordWrap = true;
            veldje_txt.multiline = true;
            veldje_txt.embedFonts = true; //turn this of and on to see the difference..
            veldje_txt.selectable = false;
            veldje_txt.antiAliasType = "advanced";
            veldje_txt.thickness = 100;
            veldje_txt.sharpness = 10;
            veldje_txt.setNewTextFormat(my_fmt);

            veldje_txt.styleSheet = astyles;
            veldje_txt.html = true;
            veldje_txt.selectable = true;
            veldje_txt.type = "dynamic";
            veldje_txt.htmlText = "<b>This </b>should be bold";
            veldje_txt.htmlText += "<font face='csverdana'><b>This should be boldt</b><i> and this should be italic</i></font>";
            veldje_txt.htmlText +="<font face='csverdanavet'>Displays as either Times or Times New Roman...</font>";
            veldje_txt.htmlText +="<font face='csverdanaitalic'>Dit is schuine tekst</font>";
            veldje_txt.htmlText +="<font face='csverdanaitalicvet'>Dit is vet en schuine tekst</font>";

            and in my library i have all the kind of same fonts.
            So it is a lot of work ... if you use one font, in this case i have to make
            4 types. ..But if i want to use more.. then do the Math!
            I don't think this should be so much work.. but this is the price you
            have to pay if you want people to change there own tekst in a simple html editor.... :(
            • 3. Re: embed fonts (html = true)  -&gt;createTextField
              kglad Adobe Community Professional & MVP
              that's a little messier than necessary, but there's no way that will decrease the number of fonts you have to embed. and overall you'll have the same amount of code or more if you use a cleaner, more modularized approach. if i were you, i'd stick with that because it's working.
              • 4. Re: embed fonts (html = true)  -&gt;createTextField
                script
                Michealnl,

                Today I got the same problem and I found a simple solution to parse the text.

                You can use split and join to add the another things, form example:

                var tempText = myString;
                tempText = tempText.split("<b>").join("<FONT FACE='bodyBold'><B>");
                tempText = tempText.split("</b>").join("</B></FONT>");

                - Only work with setNewTextFormat when you set the default font
                - You must have the 2 fonts in the library.

                regards