package
{
importflash.display.Loader;
importflash.display.Sprite;
importflash.events.Event;
importflash.events.ProgressEvent;
importflash.net.URLRequest;
importflash.system.LoaderContext;
importflash.text.Font;
importflash.text.TextField;
importflash.text.TextFormat;
importflash.utils.getDefinitionByName;
/**
* lite3@qq.com
* www.litefeel.com
* @author lite3
*/
[SWF(width=600,height=50)]
publicclassEmbedFontDemoextendsSprite
{
privatevartxt:TextField;
privatevarfontLoader:Loader;
publicfunctionEmbedFontDemo():void
{
txt=newTextField();
txt.x=50;
txt.y=10;
txt.width=500;
txt.height=30;
txt.border=true;
txt.textColor=0x0099FF;
addChild(txt);
fontLoader=newLoader();
fontLoader.load(newURLRequest("http://litefeel.com/assets/swf/embedFontDemo/font.swf"),newLoaderContext(false,loaderInfo.applicationDomain));
fontLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
fontLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,progressHandler);
}
privatefunctionprogressHandler(e:ProgressEvent):void
{
varratio:int=e.bytesLoaded/e.bytesTotal*100;
txt.text="loading... "+ratio+"%";
}
privatefunctioncompleteHandler(e:Event):void
{
fontLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeHandler);
fontLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,progressHandler);
trace("font coomplete!");
varMyFont:Class=getDefinitionByName("cn.lite3.font.Font_hyqytj")asClass;
// 注册全局字体
Font.registerFont(MyFont);
varmyFont:Font=newMyFont()asFont;
// 应用字体
varformat:TextFormat=newTextFormat(myFont.fontName,25,null,true);
txt.defaultTextFormat=format;
// 嵌入字体
txt.embedFonts=true;
txt.text="lite3 欢迎大家访问我的博客 www.litefeel.com";
}
}
}