Runtime fonts in Flash Builder 4

I am trying to get the following example to work in Flash Builder 4:

http://developer.yahoo.com/flash/articles/runtime-fonts-as3.html

The Actionscript project compiles, but all I get on the screen is a small rotated square with no text.

Does anyone know why this might happen? My code is identical to the above example - I compiled the first class in _Arial.swf.

edit

I also tried this:

package {  
    import flash.display.Sprite;  
    import flash.display.Loader;  
    import flash.events.Event;  
    import flash.net.URLRequest;  
    import flash.text.*;  

    public class _Arial extends Sprite {
        [Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', fontFamily='myFont', mimeType='application/x-font')]  
        public static var _Arial:Class;  

        public function _Arial():void {  
            drawText();
        }

        public function drawText():void {  
            var tf:TextField = new TextField();  
            tf.defaultTextFormat = new TextFormat("_Arial",60,0);
            tf.embedFonts = true;  
            tf.antiAliasType = AntiAliasType.ADVANCED;  
            tf.autoSize = TextFieldAutoSize.LEFT;  
            tf.border = true;  
            tf.text = "Scott was here\nScott was here too\nblah scott...:;*&^% ";  
            tf.rotation =  15;
            addChild(tf);
            trace(Font.enumerateFonts());
        }  
    }
}


var fontList:Array = Font.enumerateFonts(false);
for (var i:uint=0; i<fontList.length; i++) {
    trace("font: "+fontList[i].fontName);
}

Trace Displays: Font: _Arial

+3
source share
4 answers

Ok, I got it for work ... I started with this

   public class _Arial extends Sprite
{

    [Embed(source='fonts/Arial.ttf', fontName='_Arial',
    mimeType="application/x-font-truetype",
        unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E',
    embedAsCFF= "false")]
    public static var _Arial:Class; 

}

and to test it, I added that

  public function _Arial():void
  {
    var tf:TextField = new TextField();
    tf.defaultTextFormat = new TextFormat ( "_Arial" , 24 , 0 );
    tf.autoSize = TextFieldAutoSize.LEFT;           
            tf.embedFonts = true;
    tf.text = "This is some text to test!";
    tf.rotation = 20;
    addChild(tf);

  }

, , !!!

+4

, SWF SWF , , , , , , embedFonts true, , , , . , ...

, , .

, , , .

, , - , .

[Embed(source='fonts/Arial.ttf', fontName='_Arial', 
    mimeType="application/x-font-truetype",
    unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-   U+0060,U+0061-U+007A,U+007B-U+007E',
    embedAsCFF= "false")]
    public class Main extends Sprite
    {
        public function Main():void
        {
          drawText();
        }
    }

...

+1

. _Arial, , . .

-, :

// embed the font
[Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', mimeType='application/x-font')]  
public static var ArialFont:Class;


// use the font
var someTextFormat:TextFormat = new TextFormat( '_Arial', 12 );
+1
source

For your application for placement in your code above, I wonder if the compiler is trying to look for the font relative to the source path, and not the root of your file system. I tried to copy the font file to the resources folder in the src folder of your project. Then refer to it in the embed statement as "/assets/ARIAL.TTF". Hope this helps.

0
source

Source: https://habr.com/ru/post/1759507/


All Articles