[AS3]AS3.0添加外部嵌入字体的介绍说明(2)
package { importflash.display.Loader; importflash.display.Sprite; importflash.events.Event; importflash.events.ProgressEvent; importflash.net.URLRequest; importflash.system.LoaderContext; importflash
- 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.cuplayer.com/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 ratio:int = 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";
- }
- }
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...