Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Embedding font as3

Participant ,
Nov 14, 2010 Nov 14, 2010

Hi!

Im trying to embed a font in a actionScript project in Flash Builder like this:

package {
     import flash.display.*;
     import flash.text.*;
     
     public class HelloWorldEmbedded extends Sprite {
          
          // Embed the font Verdana
          [Embed(source="Verdana.ttf", fontFamily="Verdana")]
          private var verdana:Class;
          
          public function HelloWorldEmbedded() {
               
               var t:TextField = new TextField();
               
               // Tell Flash Player to use embedded fonts when rendering t's content
               t.embedFonts = true;
               
               t.htmlText = "<FONT FACE='Verdana'>Hello world</FONT>";
               t.text = "Hello World";
               
               addChild(t)
          }
     }
}

But when i debug my application i can't see any text!

This is the link of my project http://www.emmelledesign.it/eas3_fonts_embedding.fxp

Thanks so much!

Matteo

TOPICS
ActionScript
12.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 15, 2010 Nov 15, 2010

Oh, I see. This is SDK issue. You didn't have to do that in versions prior to 4. I am using 3.5

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 15, 2010 Nov 15, 2010

Good to know!

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2010 Nov 14, 2010

This is regarding your previous post with "in assets folder i have Pilgiche.ttf file!"

You will not see text

"<FONT FACE='Pilgiche'>Hello world</FONT>"

because it doesn't work in principal, it is not supposed to work without either TextFormat or StyleSheet

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 14, 2010 Nov 14, 2010

The following two classes prove that embedded fonts are available globally:

package {
     import flash.display.Sprite;
     public class FontTest extends Sprite {
          [Embed(source="Verdana.TTF", fontFamily="Verdana")]
          public var verdana:String;
          [Embed(source="CURLZ___.TTF", fontFamily="Arial")]
          public var arial:String;
          public function FontTest() {
               var fontTest:FontTestChild = new FontTestChild();
               addChild(fontTest);
       }
    }
}

External class:

package 
{
     import flash.display.Sprite;
     import flash.text.AntiAliasType;
     import flash.text.GridFitType;
     import flash.text.StyleSheet;
     import flash.text.TextField;
     import flash.text.TextFieldAutoSize;
     public class FontTestChild extends Sprite
     {
          public function FontTestChild()
          {
               var style:StyleSheet = new StyleSheet();
               style.setStyle(".redFont", { fontFamily: "Verdana", fontSize: 50, color: "#ff0000" } );
               style.setStyle(".greenFont", { fontFamily: "Arial", fontSize: 30, color: "#008000"} );
               style.setStyle("p", { fontFamily: "Arial", fontSize: 100, color: "#000080"} );
               var label:TextField = new TextField();
               label.embedFonts = true;
               label.autoSize = TextFieldAutoSize.LEFT;
               label.antiAliasType = AntiAliasType.ADVANCED;
               label.gridFitType = GridFitType.PIXEL;
               label.sharpness = -200;
               label.styleSheet = style;
               label.htmlText = "<p>AHA!!! <span class='redFont'>Hello world!</span><span class='greenFont'> It works!</span></p>";
               addChild(label);
          }
     }
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 15, 2010 Nov 15, 2010

Solved!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines