AS3.0 嵌入英文字体

时间:2022-08-24 06:10:28

把字体嵌入库可以在库面板来嵌入,在库里点右键,新建字形

AS3.0 嵌入英文字体

 

字符范围把需要的选中:

AS3.0 嵌入英文字体

设置名字

AS3.0 嵌入英文字体

接下来是代码了:

package module.ceshi
{
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    /**
     * ...
     * @author fanpengfei
     */
    public class ceshiLost extends Sprite
    {
        private var _currLoader:Loader;
        
        public function ceshiLost()
        {
            _currLoader = new Loader();
            var loaderInfo:LoaderInfo = _currLoader.contentLoaderInfo;
            loaderInfo.addEventListener(Event.COMPLETE, _levelLoaded);
            _currLoader.load(new URLRequest("Ceshi.swf"));
        }
        
        private function _levelLoaded(e:Event):void
        {
            Font.registerFont(_currLoader.contentLoaderInfo.applicationDomain.getDefinition('myFont') as Class);
            var fontLibrary:Array = new Array();
            fontLibrary = Font.enumerateFonts(false);
            var msg:TextField = new TextField();
            msg.embedFonts = true;
            msg.autoSize = TextFieldAutoSize.LEFT;
            var fmt:TextFormat = new TextFormat(fontLibrary[0].fontName, 50);
            msg.defaultTextFormat = fmt;
            msg.text = 'My name is Fanpengfei!';
            addChild(msg);
        }
    
    }

}
AS3.0 嵌入英文字体