ActionScript 3 AS3在运行时加载和访问外部SWF中的字体
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3在运行时加载和访问外部SWF中的字体相关的知识,希望对你有一定的参考价值。
///////////////////////////////////////////////////////////////////////////////////////////
// FontSwfDocumentClass.as (Publish this to create FontSWF.swf, which we will then load in to our main application below)
//
package {
import flash.display.Sprite;
public class FontSwfDocumentClass extends Sprite {
// This font was downloaded from here ...
// http://www.dafont.com/sketchetik.font
[Embed(source = "C:/Users/Adrian/Desktop/Sketchetik-Light.otf",
fontName = "Sketchetik-Light",
fontStyle = "normal",
fontWeight = "normal",
unicodeRange = "U+0020-003C,U+003E-007E,U+00A0,U+00A3,U+00A9,U+00AC,U+00AE,U+00BA,U+2013,U+2018-2019,U+201C-201D,U+20AC",
mimeType = "application/x-font",
advancedAntiAliasing = true
,embedAsCFF=false)]
public static var SketchetikLight:Class;
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// This is the Document Class that actually loads in the FontSWF and uses the embedded font
//
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.AntiAliasType;
import flash.text.Font;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
loadFontSwf("FontSWF.swf");
}
private function loadFontSwf(url:String):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onFontSwfLoaded);
loader.load(new URLRequest(url));
}
private function onFontSwfLoaded(e:Event):void {
var FontLibrary:Class = e.target.applicationDomain.getDefinition("FontSwfDocumentClass") as Class;
Font.registerFont(FontLibrary.SketchetikLight);
drawText();
}
public function drawText():void {
var tfmt:TextFormat = new TextFormat();
tfmt.color = 0x000000;
tfmt.size = 150;
tfmt.font = "Sketchetik-Light";
var tf:TextField = new TextField();
tf.defaultTextFormat = tfmt;
tf.antiAliasType = AntiAliasType.ADVANCED;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.embedFonts = true;
tf.width = 800;
tf.height = 600;
tf.x = 100;
tf.y = 100;
tf.border = true;
tf.rotation = 15;
tf.text = "Hello World";
addChild(tf);
}
}
}
// Handy URLs ...
// http://blog.madebypi.co.uk/2011/02/28/fontswffer-1-1/
// http://nochump.com/blog/archives/20
// http://www.tillschneidereit.de/unicode_range_tool.html
// http://yourpalmark.com/2009/04/05/embedding-fonts-using-external-swf-files/
// http://blog.flexexamples.com/2007/10/25/embedding-fonts-from-a-flash-swf-file-into-a-flex-application/
以上是关于ActionScript 3 AS3在运行时加载和访问外部SWF中的字体的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 AS3加载和使用外部CSS文件
ActionScript 3 AS3加载和播放外部FLV文件
ActionScript 3 AS3加载和显示外部SWF文件
ActionScript 3 AS3:加载外部.txt和.css
ActionScript 3 AS3加载和播放外部MP3文件
ActionScript 3 AS3:使用加载程序进行SWF,JPEG,GIF和PNG