`
wgcode
  • 浏览: 579505 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

AS3.0调用外部嵌入字体

阅读更多

 

首先在新建个fla命名为font.fla, Ctrl+L 调出库面板.
右键点击库面板的空白处,新建字体.... 调出 字体元件属性 窗口.
选择要嵌入的字体, 并选择为ActionScript 导出. 填入自己的类名.
点击在新窗口中打开图片

确定并Ctrl+Enter 导出 font.swf
OK,字体库已经准备就绪了,下面是应用篇 
下面是应用篇的为文档类.
提示:

Font.registerFont(MyFont); 注册全局字体 
new TextFormat(myFont.fontName); 应用字体 
txt.defaultTextFormat = format; 设置嵌入字体 
以上3条必须同时用到才OK的.

package   
{  
 import flash.display.Loader;  
 import flash.display.Sprite;  
 import flash.events.Event;  
 import flash.events.ProgressEvent;  
 import flash.net.URLRequest;  
 import flash.system.LoaderContext;  
 import flash.text.Font;  
 import flash.text.TextField;  
 import flash.text.TextFormat;  
 import flash.utils.getDefinitionByName;  
   
 /**  * lite3@qq.com  * www.lite3.cn  * @author lite3  */  
 [SWF(width=600, height=50)]  
 public class EmbedFontDemo extends Sprite   
 {  
  private var txt:TextField;  
  private var fontLoader:Loader;  
  public function EmbedFontDemo():void   
  {  
   txt = new TextField();  
   txt.x = 50;  
   txt.y = 10;  
   txt.width = 500;  
   txt.height = 30;  
   txt.border = true;  
   txt.textColor = 0x0099FF;  
   addChild(txt);  
   
   fontLoader = new Loader();  
   fontLoader.load(new URLRequest("http://www.lite3.cn/assets/swf/embedFontDemo/font.swf"),   
new LoaderContext(false, loaderInfo.applicationDomain));  
   fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);  
   fontLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);  
  }  
   
  private function progressHandler(e:ProgressEvent):void   
  {  
   var ratiint = e.bytesLoaded / e.bytesTotal * 100;  
   txt.text = "loading...  " + ratio + "%";  
  }  
   
  private function completeHandler(e:Event):void   
  {  
   fontLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, completeHandler);  
   fontLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, progressHandler);  
   trace("font coomplete!");  
   var MyFont:Class = getDefinitionByName("cn.lite3.font.Font_hyqytj") as Class;  
   
   // 注册全局字体  
   Font.registerFont(MyFont);  
   var myFont:Font = new MyFont() as Font;  
   // 应用字体  
   var format:TextFormat = new TextFormat(myFont.fontName, 25, null, true);  
   txt.defaultTextFormat = format;  
   // 嵌入字体  
   txt.embedFonts = true;  
   txt.text = "lite3 欢迎大家访问我的博客 www.lite3.cn";  
  }  
 }  
}  
 源码下载:http://www.lite3.cn/assets/soundCode/embedFontDemo.rar

font.swf 下载地址:http://www.lite3.cn/assets/swf/embedFontDemo/font.swf

 

分享到:
评论
1 楼 Ring008 2011-07-05  
貌似不对吧。那个swf链接我打开空白的

相关推荐

Global site tag (gtag.js) - Google Analytics